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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With