Mixed Models and Random Intercepts
Every model so far in this course has trusted each row on its own: one customer, one claim, one account, each an independent draw. But data rarely arrives that tidy. It comes in groups (patients within a clinic, students within a school, repeated visits from the same person) and rows inside a group resemble each other in ways the model has to respect.
Meet Dr. Anna Reyes, who runs a network of eight walk-in clinics. Every clinic delivered the same recovery programme and scored each patient's recovery from 0 to 100. One clinic saw 40 patients; another saw just 2. Two questions keep her up at night: how good is each clinic really, and can she trust a tiny clinic whose two patients happened to score high? A mixed model answers both, by letting every clinic keep its own baseline while borrowing strength from the whole network.
By the end of this lesson you will be able to:
- Say why treating grouped observations as independent is a mistake, and why the two obvious fixes both fail
- Fit a random-intercept model in R and read its two variance components
- Read the intraclass correlation (ICC): how much of the variation is between clinics rather than within
- Explain partial pooling: why the shakiest small clinics get pulled hardest toward the average
Prerequisites: you can fit and read an ordinary linear model, and you are comfortable with variance, standard deviation, and a factor column in R.
Eight clinics, wildly different sizes
Here is Dr. Reyes's network, built right here so every line on this page runs. Eight clinics, each with its own true baseline recovery level, and a very unequal number of patients. We bring in a predictor later; for now, just the clinic each patient attended and their recovery score:
Now the headline problem. Put each clinic's patient count next to its raw average recovery:
Ashby looks spectacular: an average of 78, far above everyone else. But it saw only 3 patients. Should Dr. Reyes crown it the best clinic in the network, or is three patients simply too few to trust? The bar chart makes the imbalance plain: a couple of towering bars built on almost no evidence, the rest bunched together on solid samples.