I've been asked to provide a linear equation for a lme4:lmer() model that I report in one paper.

I tried to adapt examples from http://rpsychologist.com/r-guide-longitudinal-lme-lmer but this is not my area of expertise and I would like to avoid any guesswork.

Given a repeated measurement experiment dataset where:

  • A and B are 2-level factors fully balanced within-subjects
  • C is a dichotomous (yes or no response) independent variable
  • Y is the outcome
  • The 3-way interaction within fixed effects is of main interest

How can I write down a regression style statistical equation for two lmer() mixed-effects models where:

  1. random slopes are correlated
    lmer(Y ~ A*B*C + (A*B*C | Subj), data)
  2. random slopes are uncorrelated due to convergence errors
    lmer(Y ~ A*B*C + (A*B*C || Subj), data)

PS. Reproducible example of a dataset that simulates my real experiment is posted here: Compute partial η2 for all fixed effects anovas from a lme4 model


The variant with correlated random slopes is your model 1. The variant without correlation is not easily possible using lmer, due to A and B being categorical.

My package afex offers two solutions:

  1. lmer_alt which is a wrapper for lmer that allows this. Note that in this case care should be taken that the factor codings are appropriate for interactions with categorical covriates (e.g., "contr_sum").

  2. mixed(.., expand_re = TRUE). In your case:
    mixed(Y ~ A*B*C + (A*B*C || Subj), data, expand_Re = TRUE).
    The benefit of using mixed is that it automatically uses appropriate orthogonal contrasts and calculates p-values for the effects.

Information on how afex achieves this is given in section Expand Random Effects in ?afex::mixed.

| cite | improve this answer | |
  • $\begingroup$ I did not make myself clear here. I'm interested in mathematical formula expression for those two models. I'm perfectly aware which model is which. I just don't know how to write it down a statistical equation (no R code) $\endgroup$ – blazej Jul 31 '18 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.