[R] VarCorr function for assigning random effects: was Question

Doran, Harold HDoran at air.org
Thu Sep 1 18:00:24 CEST 2005

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:
> If you are indeed using lme and not lmer then the needed function is 
> VarCorr(). However, 2 recommendations. First, this is a busy list and 
> better emails subject headers get better attention. Second, I would 
> recommend using lmer as it is much faster. However, VarCorr seems to 
> be incompatible with lmer and I do not know of another function to 
> work with lmer.

I hope that VarCorr is compatible with lmer.  It is intended to be

> library(lme4)
Loading required package: Matrix
Loading required package: lattice
> example(VarCorr)

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.

> Hence, a better email subject header will attract the attention of 
> others *much* smarter than me!
> I hope this helps,
> Harold
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Mahmoud Torabi
> Sent: Wednesday, August 31, 2005 9:51 PM
> To: R-help at stat.math.ethz.ch
> Cc: mtorabi at math.carleton.ca
> Subject: [R] Question
> Dear Sir/Madam
> I would be pleased if anybody can help me. I'm using linear mixed 
> model
> (lme) function.I'm doing some simulation in my research and need to be 
> assigned variance components values during of my program. 
> Specifically, when I use lme function, I can get some information by 
> use summary() and I can assign some valuse like variance of fixed 
> parameters and variance of random error term by using for example  
> varFix and sigma.But I don't know how I can assign for variance of random effect.
> I know in SPLUS we have command var.ran, how about R ?

The development version of the Matrix package, available at


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

More information about the R-help mailing list