Concept map / HLM

Share

Partial pooling in multilevel models

Compare school means estimated separately, estimated together, and estimated with partial pooling.

Prerequisites Regression, Likelihood

1Nine schools, three ways to estimate their means

Nine schools take the same test. School A tested 3 students; Schools H and I tested 40 each. A mean of three scores swings a lot by chance, so small schools tend to land at the top or the bottom of a ranking.

You can keep each school’s own mean (no pooling), give every school the overall mean (complete pooling), or take a weighted average of the two (partial pooling), the same compromise a posterior mean strikes between data and prior. Change τ, the spread between schools, and σ, the spread of students within a school, and watch which estimates shift most.

020406080100School (students)Test scoreoverall mean 49.4A (3)B (4)C (6)D (8)E (12)F (18)G (25)H (40)I (40)
StudentSchool's raw meanEstimateOverall mean

School A has 3 students and a raw mean of 65.6. Its weight is 0.43, so partial pooling keeps 43% of the gap between 65.6 and the overall mean of 49.4. It reports 56.3, a move of 9.3 points.

More controls

The sliders stretch the same students. New schools draws a fresh set.

2Four students or forty: which school comes out ahead?

Two schools score above the overall mean of 50. The small school tested 4 students and has a raw mean of 62. The large school tested 40 and has 58. Take τ = 5 and σ = 10, as in the lab. On raw means the small school ranks first. Which school has the higher estimate after partial pooling?

455055606570Test scoreoverall mean 50Small school4 students, mean 62Large school40 students, mean 58
Raw meanMargin of error (one standard error each side)

3The weight is the reliability of a school mean

A school's weight λ compares two variances. One is τ², how much the schools truly differ. The other is σ² / n, how noisy a mean of n students is. Few students make the noise term big and the weight small. Read this way, λ is the reliability of the school mean: the share of the spread in raw means, for schools of that size, that reflects real differences.

λj  =  τ2τ2+σ2/nj\htmlClass{term-theta}{\lambda_j} \;=\; \frac{\tau^2}{\tau^2 + \sigma^2 / n_j}

School A: 25.00 / (25.00 + 100.00 / 3) = 25.00 / 58.33 = 0.43

estimatej  =  λj×yˉj  +  (1−λj)×μ^\text{estimate}_j \;=\; \htmlClass{term-theta}{\lambda_j} \times \htmlClass{term-data}{\bar{y}_j} \;+\; (1 - \htmlClass{term-theta}{\lambda_j}) \times \htmlClass{term-prior}{\hat{\mu}}

School A: 0.43 × 65.6 + 0.57 × 49.4 = 56.3. Point at a symbol to light up its part of the chart in section 1.

All nine weights, and the intraclass correlation
A (n = 3)0.43
B (n = 4)0.50
C (n = 6)0.60
D (n = 8)0.67
E (n = 12)0.75
F (n = 18)0.82
G (n = 25)0.86
H (n = 40)0.91
I (n = 40)0.91

Drop the n and the same two variances give the intraclass correlation: τ² / (τ² + σ²) = 25.00 / 125.00 = 0.20. So 20% of the score variance lies between schools. It is the weight a school would get from one student, and the correlation between two students from the same school.

The lab treats τ and σ as known and takes them from the sliders. A real analysis estimates them. From these students, a simple method of moments gives τ ≈ 3.0 and σ ≈ 9.9. The overall mean is an average of the school means, each weighted by how precisely it is known.

A common misreading is that pooling punishes small schools. It pulls them toward the middle from either side, so a three-student school with a low raw mean is pulled up as far as one with an equally high mean is pulled down.

4Regression lines are pulled too

Schools can differ in slope as well as level. Give each student a number of study hours and fit one line per school, as on the regression page. A random-slopes model then pulls each school's line toward the average line, and lines fitted to a handful of students move most.

Show the regression lines
204060800246810Test scoreHours of study
School A's studentsIts own line (dashed)Its pooled lineOther schoolsAverage line

Fitted to its own 3 students, School A's line rises 2.03 points per hour of study. The average line rises 1.54. Partial pooling gives it 1.54, which cuts its distance from the average slope from 0.49 to 0.00.

Line heights and student scores still use τ = 5.0 and σ = 10.0 from section 1. With a height and a slope per school the weight becomes a 2 × 2 matrix, so the two are pulled together. The rule has not changed: few students or noisy scores mean a strong pull.

5Check yourself

The tasks use the controls in section 1 and tick themselves when you meet them.

  • Select School A (3 students) and move the sliders until its weight reaches 0.75. Three students are then mostly believed.Now: School A (3 students) has weight 0.43; τ = 5.0, σ = 10.0
  • Select School H or I (40 students each) and, with τ above zero, push its weight below 0.50. Now even 40 students count for less than the overall mean.Now: School A (3 students) has weight 0.43; τ = 5.0, σ = 10.0
  • With partial pooling on, find a setting where the estimates put two schools in a different order from their raw means. New schools, under More controls, draws a fresh set to try.Now: The order of the schools is the same before and after shrinkage

6Fit the same model with lme4

The snippet simulates nine schools with the page’s sizes, τ = 5 and σ = 10, and fits them with lmer(). The printed weights match section 3, from 0.43 for School A to 0.91 for H and I. Nine schools give little to estimate a spread from, so the fitted τ and σ can land some way from 5 and 10.

Fit a random-intercept model with lme4Show the code
library(lme4)
# Nine schools with the page's sample sizes
set.seed(30)
n <- c(3, 4, 6, 8, 12, 18, 25, 40, 40)
school <- factor(rep(LETTERS[1:9], n))
# Overall mean 50, tau = 5 between schools, sigma = 10 within
effect <- rnorm(9, 0, 5)
score <- 50 + effect[school] + rnorm(sum(n), 0, 10)

# Random-intercept model: estimated tau and sigma
fit <- lmer(score ~ 1 + (1 | school))
print(VarCorr(fit), comp = "Std.Dev.", digits = 2)

# The weight on each school's own mean at tau = 5, sigma = 10
round(setNames(5^2 / (5^2 + 10^2 / n), LETTERS[1:9]), 2)
# Intraclass correlation at the same values
5^2 / (5^2 + 10^2)

# Raw school means beside the partial-pooling estimates
raw <- tapply(score, school, mean)
round(cbind(n, raw, pooled = coef(fit)$school[, 1]), 1)

Uses lme4. Install once with install.packages(c("lme4")).

What partial pooling does