# Including a predictor as both crossed and nested in lmer

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?

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).)