Skip to content
Prev 76554 / 398502 Next

VarCorr function for assigning random effects: was Question

You are correct, VarCorr IS compatible with lmer. It must be what you state below. I should have saved the message but VarCorr() complained that I was not dealing with an lme() object. I had multiple packages (nlme, Matrix, mlmRev, among others) in the search path.
On 9/1/05, Doran, Harold <HDoran at air.org> wrote:
I hope that VarCorr is compatible with lmer.  It is intended to be
Loading required package: Matrix
Loading required package: lattice
VarCrr> (fm2 <- lmer(Reaction ~ Days + (1 | Subject) + (0 +
    Days | Subject), sleepstudy))
Linear mixed-effects model fit by REML
Formula: Reaction ~ Days + (1 | Subject) + (0 + Days | Subject) 
   Data: sleepstudy 
      AIC      BIC    logLik MLdeviance REMLdeviance
 1753.669 1769.634 -871.8346   1752.047     1743.669
Random effects:
 Groups   Name        Variance Std.Dev.
 Subject  (Intercept) 627.571  25.0514 
 Subject  Days         35.858   5.9881 
 Residual             653.584  25.5653 
# of obs: 180, groups: Subject, 18; Subject, 18

Fixed effects:
            Estimate Std. Error  DF t value  Pr(>|t|)    
(Intercept) 251.4051     6.8854 178 36.5128 < 2.2e-16 ***
Days         10.4673     1.5596 178  6.7117 2.480e-10 ***
---
Signif. codes:  0 $-1????***???? 0.001 ????**???? 0.01 ????*???? 0.05 ????.???? 0.1 ???? ???? 1 

VarCrr> VarCorr(fm2)
 Groups   Name        Variance Std.Dev.
 Subject  (Intercept) 627.571  25.0514 
 Subject  Days         35.858   5.9881 
 Residual             653.584  25.5653 

What may have occurred is that you had the nlme package loaded after the lme4 (actually the important package is Matrix which gets loaded by lme4) package was loaded.  The VarCorr generic in nlme would mask the VarCorr generic in the Matrix package.
The development version of the Matrix package, available at

https://svn.r-project.org/R-packages/trunk/Matrix

and soon to be Matrix_0.98-6 has a "simulate" method for lmer objects that may be of interest to you.