I am using glmer and I wish to extract the standard deviation of the variance components of the random effects (intercept and slope).
I have tried using:
VarCorr(model)
which returns the two standard deviation values (plus the correlation), but I just wish to extract the Intercept and Slope SD values.
I tried using:
VarrCorr(model)[1]
to extract the random intercept SD, which lets me know that:
attr(,"stddev")
(Intercept) year
0.075 0.011
but I don't know how to extract these as individual elements.
There are 2 ways to do this.
## make up a model
library(lme4)
(gm <- glmer(incidence ~ period + (size | herd),
family = poisson, data = cbpp))
The current version of lme4 allows you to coerce a VarCorr object to a data frame:
as.data.frame(VarCorr(gm))
Then you can select rows 1:2 and column 5 to extract standard deviations of random intercept and slope.
If you want to extract the values in a old-fashioned way, you can use attributes:
attributes(VarCorr(gm)$herd)$stddev
(Intercept) size
1.18970662 0.08826278
If you want to get rid of the names (i.e., (intercept), size), then you can use as.numeric or unname.
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