I am trying to fit a three-level model with lme4, I got familiar with the notation about equation. But I am not able to express the random effects properly in level two and three, I have:

  • on level two: random intercept
  • on level three: random intercept and random slope

For example in:

time | therapist / subjects

How can I drop random slope on level two only while having both random slopes and intercepts on level three?


1 Answer 1


In this type of scenario it is useful to recall that

(1 | A / B) 

is the same as

(1 | A) + (1 | A:B)

which also generalises to models with more levels.

Thus, in the case mentioned in the question, where we want random slopes only on the higher level, we would have:

(time | therapist) + (1 | therapist:subject)

In the case of further hierarchy of nesting, with subject nested in therapist and therapist nested in clinic, where we wanted random slopes for the fixed effect time only at the middle level, we can specify this as:

(1 | clinic) + (time | clinic:therapist) + (1 | clinic:therapist:subject)
  • $\begingroup$ Nice answer, Robert! For your 2-level model example, can you clarify whether (i) subjects are nested in therapists and (ii) subjects are measured multiple times on an outcome variable, so that time is a subject-level predictor? $\endgroup$ Commented Feb 8, 2020 at 16:49
  • 1
    $\begingroup$ In practice, would you fit the most complete model, (time | clinic) + (time | clinic:therapist) + (time | clinic:therapist:subject), and then see if you can simplify it? Or use theoretical considerations to decide at what level to include random slopes for time? Or a blend of both? $\endgroup$ Commented Feb 8, 2020 at 16:56
  • 4
    $\begingroup$ @IsabellaGhement Thank you. it wasnt specified in the question at what level time varies but I implicitly assumed it would vary at the level appropriate to the model, in both models. I agree it would be possible (though not necessarily better) to allow it to vary at other levels unless there was good reason for it not to, but the question was quite specific that they didn't want that. Personally I always look for theoretical justification for the whole random structure (I disagree with Barr at all 2013 on this and instead prefer to follow Bates in "Parsimonious Mixed Models") $\endgroup$ Commented Feb 8, 2020 at 18:30
  • 2
    $\begingroup$ Agreed, @RobertLong. Not to mention the fact that the estimation gets trickier the more complex the random structure, and in the maximal case may require Bayesian approaches. That's not a deal breaker, but a lot of folks simply don't understand the particulars and implications of the Bayesian approach. $\endgroup$
    – Erik Ruzek
    Commented Feb 8, 2020 at 20:32
  • 1
    $\begingroup$ @Adel No, in that formula you have random slopes only at the level 1. If you want it also on level 3 (clinic) you would write :(time | clinic) + (1 | clinic:therapist) + (time | clinic:therapist:subject) $\endgroup$ Commented Feb 25, 2020 at 15:44

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.