Solved – Random slopes for interactions without random slopes for main effects

glmmlme4-nlme

I have a GLMM with the following form:

m1 <- glmer(Y ~ A*B + (A*B|Subject), data, family=binomial(logit))

where A and B are categorical factors with 2 levels, and Subject is my grouping factor, with a relatively small number of levels (e.g., 10). A likelihood ratio test indicates that the random slope for the interaction A:B makes a significant contribution to the fit of the model, so I keep it.

Let's say I have no prior hypothesis about the structure of the random effects, and I want to find the model that provides the best and most parsimonious description of the data. Does it makes sense to proceed testing random slopes for the main effects?

More specifically, is it appropriate to compare (with a likelihood ratio test) the model above (m1) with this reduced model where I removed the random component for one of the main effects?

m2 <- glmer(Y ~ A*B + (A + A:B|Subject), data, family=binomial(logit))

I would say that intuitively it makes sense, as m2 would be a model where the effect of B is pretty much constant for all subjects, while the magnitude of the interaction A:B varies from subject to subject. However I am wondering whether in practice one can distinguish between variability in the effect of B vs. variability in the interaction A:B. I know that, for fixed-effects predictors, it is generally wrong to fit a model that has an interaction term without including the main effects marginal to that interaction, so I guess that I am asking whether I should respect the marginality principle also for testing random slopes.

Thanks!

Best Answer

I'm not sure this makes sense.

First of all, it won't work the way you expect: A:B will expand to a model of the same dimensionality as A*B (and lme4 isn't quite as smart as it might be about handling the redundancies

set.seed(101)
dd <- expand.grid(A=factor(1:2),B=factor(1:2),Subject=1:40,rep=1:20)
dd$Y <- simulate(~A*B+(A*B|Subject),
                 newdata=dd, family=binomial,
                 weights=rep(1,nrow(dd)),
                 newparams=list(beta=rep(1,4),
                                theta=rep(1,10)))[[1]]
library(lme4)

Your original model:

m1 <- glmer(Y ~ A*B + (A*B|Subject), dd, family=binomial)

This gives convergence warnings, and ends up with a log-likelihood 0.003 less than the original (basically, numeric fuzz)

m2 <- update(m1, . ~ A*B+(A+A:B|Subject))

This is also equivalent:

m3 <- update(m1, . ~ A*B+(A:B-1|Subject))
all.equal(logLik(m1),logLik(m3),tolerance=1e-4) ## TRUE

If you really wanted to leave out the main effect of B you'd have to use dummy variables.

For the meaning of this: can you explain what the model would mean? In particular, the model that you intend (not what lme4 actually does) when you use (A+A:B|Subject) would have among-individual variation in the effects of A, no effects of B at the baseline value of A (assuming you are using the standard treatment contrasts), but variation in the effect of adding B to A. Another analogy would be to a model with fixed intercepts but variable slopes.