Random Slopes and GLMMs
In Lesson 12 you gave each of Dr. Reyes's eight clinics its own baseline recovery level: one random intercept per clinic, all drawn from a shared bell curve. But every clinic was forced to share the same slope for therapy sessions, giving eight parallel lines. That is often too rigid. At some clinics an extra therapy session lifts recovery a lot; at others it barely moves the needle.
This lesson lets the slope vary by clinic too, so the lines fan out instead of running parallel. Then it goes one step further: when the outcome is a yes/no or a count rather than a 0-100 score, the generalized linear mixed model (GLMM) carries everything you know onto that new scale.
By the end of this lesson you will be able to:
- See why one shared slope (parallel lines) is too rigid, and fit a random-slopes model with
lmer - Read the three numbers a random slope adds: the spread of intercepts, the spread of slopes, and their correlation
- Test whether the random slope earns its keep, and watch partial pooling steady the noisy small-clinic slopes
- Diagnose and fix the two warnings every mixed-model user meets: singular fits and convergence failures
- Fit a GLMM for a yes/no outcome with
glmerand read its effect as an odds ratio
Prerequisites: Lesson 12 on random intercepts (variance components, the ICC, partial pooling), an ordinary linear model, and the logit link and odds for the GLMM half.
One shared slope, eight clinics
We are back with Dr. Anna Reyes and her eight walk-in clinics. Every lesson runs in its own session, so we rebuild her network right here. Alongside each patient's therapy sessions and 0-100 recovery score, we now record two more things: the patient's baseline illness severity (standardised), and whether, at a one-year follow-up, they recovered fully (1) or not (0). We use severity when we reach troubleshooting, and recovered for the GLMM at the end.
The question that drives this lesson: does an extra therapy session help every clinic by the same amount? Lesson 12's random-intercept model assumed yes. Let us look.