# Variance-covariance matrix in lmer

I know that one of the advantages of mixed models is that they allow to specify variance-covariance matrix for the data (compound symmetry, autoregressive, unstructured, etc.) However, lmer function in R does not allow for easy specification of this matrix. Does anyone know what structure lmer uses by default and why there is no way to easily specify it?

Mixed models are (generalized versions of) variance components models. You write down the fixed effects part, add error terms that may be common for some groups of observations, add link function if needed, and put this into a likelihood maximizer.

The various variance structures you are describing, however, are the working correlation models for the generalized estimating equations, which trade off some of the flexibility of the mixed/multilevel models for robustness of inference. With GEEs, you are only interested in conducting inference on the fixed part, and you are OK with not estimating the variance components, as you would in a mixed model. For these fixed effects, you get a robust/sandwich estimate that is appropriate even when your correlation structure is misspecfieid. Inference for the mixed model will break down if the model is misspecified, though.

So while having a lot in common (a multilevel structure and ability to address residual correlations), mixed models and GEEs are still somewhat distinct procedures. The R package that deals with GEEs is appropriately called gee, and in the list of possible values of corstr option you will find the structures you mentioned.

From the point of view of GEEs, lmer works with exchangeable correlations... at least when the model has two levels of hierarchy, and only random intercepts are specified.

• Thank you, Stas. I have not heard of GEEs before and just trying to learn mixed modeling (which is tricky and is also amplified by the differences in software implementation). I will give GEE a try. I really have a simple experiment with repeated measures with biomedical dependent measures. I am interested in the fixed part mostly. My previous training is mostly in standard fixed effects ANOVAs so it may be an easier transition. – Nikita Kuznetsov Feb 12 '13 at 21:50
• I like the idea of estimating the fixed parameters and have tried the gee library. There are other libraries too (geepack, for example). Are they worse for some reason? In my field people need to report p-values. Is there a way to get these from the estimates and also conduct pairwise comparisons taking clustering into consideration? – Nikita Kuznetsov Feb 12 '13 at 22:38
• Pairwise comparisons of what? The variety of R libraries has always been driving me nuts, and I don't research into the differences between packages unless I have a real need to work on a specific model. – StasK Feb 12 '13 at 22:56
• StatsK, is this really correct? I am a beginner in multilevel modelling but Hox (2010) or Rabe-Hesketh & Skrondal (2013) clearly distinguish between different variance estimaters via MLE and GEE. For example when calculating “robust” sandwich standard error, Hox (p. 260) says you can either calculate them via multilevel modelling using the Information matrix / inverse of the Hessian matrix (taking the multilevel structure into account) or via estimating the variance from raw residuals and using GLS afterwards to calculate the coefficients (GEE approach) – Arne Jonas Warnke Aug 29 '13 at 9:57
• I'm not sure the distinction being suggested by StasK is really correct here. While these alternative correlation structures are indeed used by GEEs, it is perfectly possible to fit (fully parametric) mixed models with more complicated structures for the covariance of either random effects or residual errors, and the nlme package in R, SAS Proc Mixed, or Stata's mixed commands do this. – Jonathan Bartlett Jan 18 '16 at 10:56

The FlexLamba branch of lmer provides such a functionality.

See https://github.com/lme4/lme4/issues/224 for examples how to implement a specific structure of errors or random effects.

• Can I have both the regular and FlexLambda branches installed at once?. How? – skan Sep 19 '15 at 12:30

To my knowledge lmer is not having an "easy" way to address this. Also given that in most cases lmer makes heavy use of sparse matrices for Cholesky factorization I would find it unlikely that it allows for totally unstructured VCV's.

To your address your question on "default structure": there is not a concept of default; depending on how you define your structure, you use that structure. Eg. using random effects like : $(1|RandEff_1)+(1|RandEff_2)$ where each random effect has 3 levels will result in unnested and independent random effects and a diagonal random effects VCV matrix of the form:

$R = \begin{bmatrix} \sigma_{RE1}^2 & 0& 0 & & 0 & 0 & 0\\ 0 & \sigma_{RE1}^2& 0 & & 0 & 0 & 0\\ 0 & 0& \sigma_{RE1}^2 & & 0 & 0 & 0\\ 0& 0& 0 & & \sigma_{RE2}^2 & 0 & 0 \\ 0 & 0& 0 & & 0 & \sigma_{RE2}^2 & 0\\ 0& 0& 0 & & 0& 0 & \sigma_{RE2}^2 \\\end{bmatrix}$

All is not lost with LME's though: You can specify these VCV matrix attributes "easily" is you are using the R-package MCMCglmm. Look at the CourseNotes.pdf, p.70. In that page it does give some analogues on how lme4 random effects structure would be defined but as you'll see yourself, lmer is less flexible than MCMCglmm in this matter.

Half-way there is problem nlme's lme corStruct classes, eg. corCompSymm, corAR1, etc. etc. Fabian's response in this tread gives some more concise examples for lme4-based VCV specification but as mentioned before they are not as explictly as those in MCMCglmm or nlme.

• I don't "trust" MCMCglmm, because of the naive choice of prior distributions. – Stéphane Laurent Feb 12 '13 at 9:38
• A. I don't think it is "naive"; they can reflect valid assumptions. You can even define improper priors if you feel that strongly for something. B. That was only part of my answer, it didn't say it is the only way to go; I gave example for lme4. C. If you need to do multivariate mixed effects it is practically the only available package along with sabreR... – usεr11852 Feb 12 '13 at 13:41
• Sorry, my comment was not a criticism about your answer. When saying "naive priors", I talked about the noninformative priors. – Stéphane Laurent Feb 12 '13 at 14:28
• It does not seem likely that this R matrix is right. Even the "classical" repeated-measures ANOVA allows for non-zero correlations between the conditions (I'm thinking of the compound symmetry matrix). Seems to me that this matrix would only be valid for a between-subject design with random assignment with two clusters. – Nikita Kuznetsov Feb 12 '13 at 21:58
• The matrix is "right"; given that I indeed defined two clusters as: $(1|RandEff_1)+(1|RandEff_2)$, it makes sense. Clearly it encodes no compound symmetry in the dynamics of the variance. – usεr11852 Feb 13 '13 at 8:48