[R] lmer / variance-covariance matrix random effects
Spencer Graves
spencer.graves at pdf.com
Mon Oct 31 03:57:12 CET 2005
Have you received a reply to this post? I haven't seen one. I agree
that VarCorr(lmer(...)) is "unhandy" if I want to do further
computations with those numbers, which I often do. The following solves
that problem, at least for the example in the lmer VarCorr documentation:
fm2 <- lmer(Reaction ~ Days + (1|Subject) + (0+Days|Subject), sleepstudy))
vc.lmer <- VarCorr(fm2)
str(vc.lmer) # to understand the structure
vc.lmer <- function(obj, sep=":"){
vc <- show(VarCorr(obj))
nR <- dim(vc)[1]
nC <- dim(vc)[2]
vc. <- as.numeric(vc[, nC-(1:0)])
colNms <- dimnames(vc)[[2]][nC-(1:0)]
vcNames <- vc[,1]
if(nC>3)for(i in 2:(nC-2))
vcNames <- paste(vcNames, vc[,i], sep=sep)
VC <- array(vc., dim=c(nR, 2),
dimnames=list(vcNames, colNms))
VC
}
(tst <- vc.lmer(fm2))
Variance Std.Dev.
Subject:(Intercept) 627.507 25.0501
Subject:Days 35.858 5.9882
Residual: 653.589 25.5654
Hope this helps.
spencer graves
Roel de Jong wrote:
> Hello,
>
> has someone written by chance a function to extract the
> variance-covariance matrix from a lmer-object? I've noticed the VarCorr
> function, but it gives unhandy output.
>
> Regards,
> Roel de Jong
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
--
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA
spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel: 408-938-4420
Fax: 408-280-7915
More information about the R-help
mailing list