Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract fixed effects part of summary from lme4?

Tags:

r

lme4

I wish to extract the fixed effects part of summary() as a data.frame. I am using lme4 to run the following model:

SleepStudy <- lmer(Reaction ~ Days + (1|Subject), data = sleepstudy)
summary(SleepStudy)

I know that I can extract the random effects section of summary by using the following:

SleepStudy_RE <- as.data.frame(VarCorr(SleepStudy))

Is there a similar line of code for the fixed effects, including the estimate, standard error, degrees of freedom and exact p-value?

Thank you.

like image 227
user2716568 Avatar asked May 20 '16 01:05

user2716568


1 Answers

coef(summary(fitted_model)) should do it.

library(lme4)
SleepStudy <- lmer(Reaction ~ Days + (1|Subject), data = sleepstudy)
coef(summary(SleepStudy))
##              Estimate Std. Error  t value
## (Intercept) 251.40510  9.7467163 25.79383
## Days         10.46729  0.8042214 13.01543

If you want p-values you need lmerTest (you need to re-fit the model):

library(lmerTest)
SleepStudy <- lmer(Reaction ~ Days + (1|Subject), data = sleepstudy)
coef(summary(SleepStudy))
##              Estimate Std. Error       df  t value Pr(>|t|)
## (Intercept) 251.40510  9.7467163  22.8102 25.79383        0
## Days         10.46729  0.8042214 161.0036 13.01543        0

I don't know why the p-values are exactly zero in this case; maybe something to take up with the lmerTest maintainers.

You may also be interested in the broom package.

like image 117
Ben Bolker Avatar answered Sep 28 '22 14:09

Ben Bolker