Reputation: 1946
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.
Upvotes: 7
Views: 10095
Reputation: 226087
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.
(As of April 10 2023 lmerTest
returns the correct/unrounded p-values (2.2e-18 and 6.41e-27) ...)
You may also be interested in the broom.mixed package.
Upvotes: 14