[R-sig-ME] extracting random effect standard deviation
bates at stat.wisc.edu
Fri Aug 1 21:15:26 CEST 2008
On Fri, Aug 1, 2008 at 1:38 PM, Daniel Ezra Johnson
<danielezrajohnson at gmail.com> wrote:
> How can I 'extract' the value of a random effect's standard deviation
> from an lmer model?
> This number is (a rather important) part of the usual lmer() output
> but I cannot figure out anywhere in str(lmer.model) where it can be
> I can get it from summary(lmer.model)@REmat[,4], but that 'extra' call
> to summary is slowing down my program.
> Obviously the model has this information in it somewhere because the
> model listing contains it.
> How can I get it out?
Use the VarCorr extractor function. This returns a list of
variance-covariance matrices so you want something like
stddevs <- function(obj)
unlist(lapply(VarCorr(obj), function(m) sqrt(diag(m))))
I'll leave it as an exercise to the reader to decide what names should
be given to these elements and to get them in the right places.
Doing that correctly in the general case is non-trivial.
I have been playing with the idea of having an optional argument
"type" for the VarCorr extractor so that the user can specify the raw
form (the factors of the relative variance-covariance matrices as
stored internally) or the variance-covariance form or the standard
deviations and correlations form or a transformed version as the
logarithm of the standard deviations and Fisher's z-transformation
(the hyperbolic arc-tangent) of the correlations. At different times
you want these estimates in different forms.
More information about the R-sig-mixed-models