# ( 3 level ) random intercept at level 2 & random slope and random intercept at level 3

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?

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)

• 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? – Isabella Ghement Feb 8 at 16:49
• 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? – Isabella Ghement Feb 8 at 16:56
• @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") – Robert Long Feb 8 at 18:30
• 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. – Erik Ruzek Feb 8 at 20:32
• @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) – Robert Long Feb 25 at 15:44