What is the default variance-covariance structure for random-effects in glmer or lmer in lme4 package? How does one specify other variance-covariance structure for random-effects in the code? I could not find any information regarding this in the lme4 documentation.


2 Answers 2


The default variance-covariance structure is unstructured -- that is, the only constraint on the variance-covariance matrix for a vector-valued random effect with $n$ levels is that is positive definite. Separate random effects terms are considered independent, however, so if you want to fit (e.g.) a model with random intercept and slope where the intercept and slope are uncorrelated (not necessarily a good idea), you can use the formula (1|g) + (0+x|g), where g is the grouping factor; the 0 in the second term suppresses the intercept. If you want to fit independent parameters of a categorical variable (again, possibly questionable), you probably need to construct numeric dummy variables by hand. You can, sort of, construct a compound-symmetric variance-covariance structure (although with non-negative covariances only) by treating the factor as a nested grouping variable. For example, if f is a factor, then (1|g/f) will assume equal correlations among the levels of f.

For other/more complex variance-covariance structures, your choices (in R) are to (1) use nlme (which has the pdMatrix constructors to allow more flexibility); (2) use MCMCglmm (which offers a variety of structures including unstructured, compound symmetric, identity with different variances, or identity with homogeneous variances); (3) use a special-purpose package such as pedigreemm that constructs a special structured matrix. There is a flexLambda branch on github that eventually hopes to provide more capabilities in this direction.

  • $\begingroup$ Maybe it's worth pointing out that xxM package is also a good but a more complicated option, which allows structure equation modelling. xxm.times.uh.edu $\endgroup$
    – User33268
    Jan 19, 2018 at 16:26

I can show this by example.

Covariance terms are specified in the same formula as the fixed and random effects. Covariance terms are specified by the way the formula is written.

For example:

glmer(y ~ 1 + x1 + (1|g) + (0+x1|g), data=data, family="binomial")

Here there are two fixed effects that are allowed to vary randomly, and one grouping factor g. Because the two random effects are separated into their own terms, no covariance term is included between them. In other words, only the diagonal of the variance-covariance matrix is estimated. The zero in the second term explicitly says do not add a random intercept term or allow an existing random intercept to vary with x1.

A second example:

glmer(y ~ 1 + x1 + (1+x1|g), data=data, family="binomial")

Here a covariance between the intercept and x1 random effects is specified because 1+x1|g is all contained in the same term. In other words, all 3 possible parameters in the variance-covariance structure are estimated.

A slightly more complicated example:

glmer(y ~ 1 + x1 + x2 + (1+x1|g) + (0+x2|g), data=data, family="binomial")

Here the intercept and x1 random effects are allowed to vary together while a zero correlation is imposed between the x2 random effect and each of the other two. Again a 0 is included in the x2 random effect term only to explicitly avoid including a random intercept that covaries with the x2 random effect.


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.