In ?lme4::ranef, it is stated:

condVar: a logical argument indicating if the conditional variance-covariance matrices of the random effects should be added as an attribute.

If condVar is TRUE, each data frame has an attribute called "postVar".

If there is a single random-effects term for a given grouping factor, this attribute is a three-dimensional array with symmetric faces; each face contains the variance-covariance matrix for a particular level of the grouping factor.

While in ?nlme::getVarCov

Extract the variance-covariance matrix from a fitted model, such as a mixed-effects model.

type: For models fit by lme() the type argument specifies the type of variance-covariance matrix, either "random.effects" for the random-effects variance-covariance (the default) or "conditional" for the conditional. variance-covariance of the responses or "marginal" for the marginal variance-covariance of the responses.

Then I try

fm1 <- lme(distance ~ age, data = Orthodont, random = ~ 1 | Subject)
lfm1 <- lmer(distance ~ age + (1 | Subject), data = Orthodont)

getVarCov(fm1, individuals = "F01", type = "conditional")
Subject F01 
Conditional variance covariance matrix
       1      2      3      4
1 2.0495 0.0000 0.0000 0.0000
2 0.0000 2.0495 0.0000 0.0000
3 0.0000 0.0000 2.0495 0.0000
4 0.0000 0.0000 0.0000 2.0495
  Standard Deviations: 1.4316 1.4316 1.4316 1.4316 

# Looking at ranef(lfm1) I see subject 'F01' is the 20th
attr(ranef(lfm1)[["Subject"]], "postVar")[, , 20]
[1] 0.4596965

Why is there this difference? Is it possible to get the lme4 var-cov matrix from a nlme model?


1 Answer 1


The difference is explained by the fact that these are two different variances. In particular, the model both lme() and lmer() fit in this case is

$$\left\{ \begin{array}{l} \texttt{distance}_{ij} = \beta_0 + \beta_1 \texttt{age}_{ij} + b_{i0} + \varepsilon_{ij}\\\\ b_{i0} \sim \mathcal N(0, \sigma_b^2), \quad \varepsilon_{ij} \sim \mathcal N(0, \sigma^2) \end{array} \right.$$

Individual F01 has four measurements, and conditional on the random intercept, these measurements are independent with variance $\sigma^2$. The conditional model is given in the first line of the equation above. This is what you get from the call getVarCov(fm1, individuals = "F01", type = "conditional").

The postVar component that you get from the call to lme4::ranef(..., ) is the posterior variance for the random effect, i.e., $\mbox{var}(b_{i0} \mid \texttt{distance}_{ij})$. I don't know if you can get this from an lme model.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.