How to get coefficients and their confidence intervals in mixed effects models?

前端 未结 6 918
無奈伤痛
無奈伤痛 2020-12-04 10:52

In lm and glm models, I use functions coef and confint to achieve the goal:

m = lm(resp ~ 0 + var1 + var1         


        
相关标签:
6条回答
  • 2020-12-04 11:15

    I'd suggest tab_model() function from sjPlot package as alternative. Clean and readable output ready for markdown. Reference here and examples here.

    For those more visually inclined plot_model() from the same package might come handy too.

    Alternative solution is via parameters package using model_parameters() function.

    0 讨论(0)
  • 2020-12-04 11:22

    I suggest that you use good old lme (in package nlme). It has confint, and if you need confint of contrasts, there is a series of choices (estimable in gmodels, contrast in contrasts, glht in multcomp).

    Why p-values and confint are absent in lmer: see http://finzi.psych.upenn.edu/R/Rhelp02a/archive/76742.html .

    0 讨论(0)
  • 2020-12-04 11:25

    There are two new packages, lmerTest and lsmeans, that can calculate 95% confidence limits for lmer and glmer output. Maybe you can look into those? And coefplot2, I think can do it too (though as Ben points out below, in a not so sophisticated way, from the standard errors on the Wald statistics, as opposed to Kenward-Roger and/or Satterthwaite df approximations used in lmerTest and lsmeans)... Just a shame that there are still no inbuilt plotting facilities in package lsmeans (as there are in package effects(), which btw also returns 95% confidence limits on lmer and glmer objects but does so by refitting a model without any of the random factors, which is evidently not correct).

    0 讨论(0)
  • 2020-12-04 11:27

    To find the coefficient, you can simply use the summary function of lme4

    m = lm(resp ~ 0 + var1 + var1:var2) # var1 categorical, var2 continuous
    m_summary <- summary(m)
    

    to have all coefficients :

    m_summary$coefficient
    

    If you want the confidence interval, multiply the standart error by 1.96:

    CI <- m_summary$coefficient[,"Std. Error"]*1.96
    print(CI)
    
    0 讨论(0)
  • 2020-12-04 11:32

    Assuming a normal approximation for the fixed effects (which confint would also have done), we can obtain 95% confidence intervals by

    estimate + 1.96*standard error.

    The following does not apply to the variance components/random effects.

    library("lme4")
    mylm <- lmer(Reaction ~ Days + (Days|Subject),  data =sleepstudy)
    
    # standard error of coefficient
    
    days_se <- sqrt(diag(vcov(mylm)))[2]
    
    # estimated coefficient
    
    days_coef <- fixef(mylm)[2]
    
    upperCI <-  days_coef + 1.96*days_se
    lowerCI <-  days_coef  - 1.96*days_se
    
    0 讨论(0)
  • 2020-12-04 11:34

    Not sure when it was added, but now confint() is implemented in lme4. For example the following example works:

    library(lme4)
    m = lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
    confint(m)
    
    0 讨论(0)
提交回复
热议问题