I am seeking statistical advice on the random-effects structure of a mixed-model. I am using R's lme4 package.

Based on recent papers showing the importance of the random-effects structure (such as http://www.sciencedirect.com/science/article/pii/S0749596X12001180), I would like to make sure that my random-structure is correct.

More specifically, I have predictors A and B and dependent variable Y.

Predictor A constitutes the experimental manipulation (every subject comes twice to the lab, undergoing treatment 1 or 2), and I have mulitple observations of the dependent variable Y (100 per participant, "ID"). B in contrast, is a nuisance variable (i.e., Hunger), which is assummed to be constant over the short time of the experiment.

Now I am not sure how to correctly specify the random effects if

a) I am interested (a priori) in the interaction between A and B. Would

summary(a<-glmer( Y ~ A * B + (1 + A*B|ID), data= x, family="binomial"), REML=FALSE)


summary(a<-glmer( Y ~ A * B + (1 + A|ID), data= x, family="binomial"), REML=FALSE)

be the correct model?

b) Assuming I am only interested in the main effect of A. B (e.g., hunger, or something that is constant over all experimental seesions, such as age) is considered a nuisance variable. Would

summary(a<-glmer( Y ~ A + B + (1 + A + B|ID), data= x, family="binomial"), REML=FALSE)


  summary(a<-glmer( Y ~ A + B + (1 + A|ID), data= x, family="binomial"), REML=FALSE)

be the correct model? Based on the post Mixed Model Analyses with Interactions in the Random Effects Structure I would suggest the second, but please let me know if I am incorrect.

Thank you, Laura


1 Answer 1


This depends on your working hypotheses.

If you believe that the interaction between $A$ and $B$ will be the same for everybody (same additive effect on the log-odds ratio) then the second model (under (a)) is appropriate. If you believe it depends on the individual, then the first form is appropriate.

If I understand the question correctly, then you are saying $B$ is constant given ID and $A$. In that case, there's no point having A*B|ID in the model since that expands to (A + B + A:B|ID) and the last term has as many levels as there are data. The "random effects" would end up being a perfect fit for the individual means.

If $B$ is constant across both sessions then it should not appear in the random effect at all. In effect you would have no way to untangle which part of the random effect was down to $B$ and which down to ID. Thus the appropriate form would be ~1+A+B+(1+A|ID).

  • $\begingroup$ Thank you very much for your quick reply. Indeed B is a constant given ID and A (in the first part of the question). So if you would not specify A*B|ID, what would you specify in that case? Thanks! $\endgroup$
    – LaNeu
    Aug 31, 2016 at 11:47
  • $\begingroup$ Assuming B has an ordinary effect and is different between sessions, 1+A+B+(1+A+B|ID). If B is the same at both sessions, then 1+A+B+(1+A|ID). $\endgroup$
    – JDL
    Aug 31, 2016 at 11:51

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.