1
$\begingroup$

I am trying to understand how lme4's mixed modeling works, specifically its random effects design matrix "Z". I have the following R code:

library(lme4)
A = as.factor(c(1,1,1,1,2,2,2,2))
B = as.factor(c(1,1,2,2,1,1,2,2))
R = c(1,2,3,4,6,7,9,11) + runif(8)
remdl = lmer(R ~ (1|A/B) + (1|B))
summary(remdl)
getME(remdl, "Z")

In this mixed effect model, I believe that I am telling lmer() to treat Predictor B as both nested within A and crossed with A. When I run this code, lmer() throws a "singular fit" error, but it does fit the model.

My question is: How is this possible? How can the random effect predictor B be treated as both nested and crossed with A?

$\endgroup$

1 Answer 1

1
$\begingroup$

The response of the model you're fitting ((1|A/B) + (1|B)) is equivalent to (1|A) + (1|A:B) + (1|B). This means that you are allowing the intercept to vary (1) among levels of A, (2) among levels of B, and (3) among combinations of A and B. As long as you have multiple observations for (most) combinations of A and B, this should be identifiable. (In glmmTMB, which has slightly updated formula-processing machinery you could also specify this model as (1|A*B).)

$\endgroup$
5
  • $\begingroup$ I understand, thanks! If I may ask a follow up question, in my example, the random effects design matrix "Z" seems to show many co-linear columns, yet the lmer() function still works. Is this design matrix not actually co-linear, or is this simply a feature of random effects design matrices that they can have co-linear columns? $\endgroup$ Commented Jul 21, 2023 at 17:27
  • 1
    $\begingroup$ You could ask it as a separate question if you want, but the answer is the latter: because the coefficients corresponding the Z matrix are penalized, coefficients for collinear columns will 'share' the effects (similar to collinear predictors in a ridge regression, if that analogy helps ...) $\endgroup$
    – Ben Bolker
    Commented Jul 21, 2023 at 17:34
  • $\begingroup$ I'm not familiar with ridge regression, but is it possible to think of collinear columns as being weighted by a their fraction (2 columns get 50% weight each; 3 columns get 33% weight each)? Also, is there any situation where adding collinear columns to a random effect design matrix would be desirable? This concept contradicts my intuition from fixed effect design matrices about what the purpose of a model coefficient is, namely to distinguish a set of data points from them rest. $\endgroup$ Commented Jul 21, 2023 at 17:54
  • 1
    $\begingroup$ Approximately, yes. Whenever you have more than one RE term in a model, the Z matrix is likely to be rank-deficient/have multicollinear columns, each component is a set of mutually exclusive indicator variables (so the sum of each set of columns is equal to 1). $\endgroup$
    – Ben Bolker
    Commented Jul 21, 2023 at 20:18
  • $\begingroup$ Great, thank you! $\endgroup$ Commented Jul 21, 2023 at 22:23

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.