[R-sig-ME] extracting variance components in lme4?

Douglas Bates bates at stat.wisc.edu
Mon Feb 5 20:27:15 CET 2007


On 2/5/07, Jerome Goudet <Jerome.Goudet at unil.ch> wrote:
> I was wondering whether anyone knew of a quick way to extract variance
> component from an lmer (or lmer2) model.  I have a random effect nested
> design (with fact2 nested in fact1) that I call as follow
>
> model1<-lmer(resp~1+(1|fact1)+(1|fact2),data=data)
>
> I can obtain the variance components from VarCorr (actually, the
> variance components of fact1 and fact2 only, and the standard deviation
> of the residuals):

> vc<-VarCorr(model1)

> but then, I can't extract the variance components and store them in a
> simple R object (I could with lme of package nlme).  I need to do that
> for further processing.

> Any clues on how I could do it )

Well vc is a list with two components named fact1 and fact2 and each
of those components is a matrix of class dpoMatrix.  If you have only
variance components (i.e. if the random effects terms in your model
formula always have the form (1|factx)) then you can extract the x
slot from those matrices.

Try

sapply(vc, slot, "x")

Be aware that this will give nonsense results if your model has random
effects for a slope as well as for an intercept.




More information about the R-sig-mixed-models mailing list