Math for Causal Inference

Day 40. Cluster Randomisation & Design Effects

Randomising schools, clinics or villages instead of individuals; the intra-cluster correlation, the design effect, and why the number of clusters is what buys power.

Video coming soon
Learning outcomes
  • ●Compute the design effect, effective sample size and variance of a cluster-randomised difference in means.
  • ●Derive the variance of a cluster mean from the intra-cluster correlation.
  • ●Calculate the minimum detectable effect and the number of clusters needed for a target power.
  • ●Choose between individual and cluster randomisation and handle unequal cluster sizes and few clusters.
2-HOUR SESSION PLAN
Theory 25′Warm-up (1–5) 20′Proofs (6–10) 35′Applied (11–15) 25′Python & Lab 15′
Colab notebook (.ipynb) Jump to the simulator

Theory

When to randomise clusters

Randomise groups (schools, clinics, villages, markets) when the intervention is delivered to groups (teacher training, a clinic protocol), when spillovers within groups are likely (Day 32), or when individual randomisation is politically or logistically impossible.

The intra-cluster correlation

Write outcomes as Yig=μ+ug+eigY_{ig} = \mu + u_g + e_{ig}, with cluster effects ugu_g (variance σu2\sigma_u^2) and individual noise eige_{ig} (variance σe2\sigma_e^2). Total variance σ2=σu2+σe2\sigma^2 = \sigma_u^2 + \sigma_e^2 and the intra-cluster correlation

ρ=σu2σu2+σe2\rho = \frac{\sigma_u^2}{\sigma_u^2 + \sigma_e^2}

is the correlation between two people in the same cluster. Typical values: 0.01–0.05 for many health outcomes, 0.1–0.3 for test scores within schools.

Variance and design effect

With clusters of size mm, each cluster mean has variance σ2[ρ+(1−ρ)/m]\sigma^2[\rho + (1 - \rho)/m]. With J1J_1 treated and J0J_0 control clusters,

Var⁡(τ^)=σ2[ρ+1−ρm](1J1+1J0)=[1+(m−1)ρ]⏟design effect×σ2(1mJ1+1mJ0).\operatorname{Var}(\hat\tau) = \sigma^2\Big[\rho + \frac{1 - \rho}{m}\Big]\Big(\frac{1}{J_1} + \frac{1}{J_0}\Big) = \underbrace{[1 + (m - 1)\rho]}_{\text{design effect}}\times\sigma^2\Big(\frac{1}{mJ_1} + \frac{1}{mJ_0}\Big).

The design effect (DEFF) inflates the individually randomised variance. As m→∞m \to \infty the variance falls only to σ2ρ(1/J1+1/J0)\sigma^2\rho(1/J_1 + 1/J_0): adding clusters helps far more than adding people per cluster.

Power

With a share PP of JJ clusters treated,

MDE=(z1−α/2+z1−β)σ2[ρ+(1−ρ)/m]P(1−P)J.\text{MDE} = (z_{1-\alpha/2} + z_{1-\beta})\sqrt{\frac{\sigma^2[\rho + (1 - \rho)/m]}{P(1 - P)J}}.

Baseline covariates measured at the cluster level reduce the between-cluster variance and are especially valuable.

Analysis

Use cluster-robust SEs (Day 29), or analyse cluster means; with few clusters, use randomisation inference at the cluster level (Day 37) or the wild cluster bootstrap. With unequal cluster sizes, decide whether the estimand weights individuals or clusters equally.

Part 1 · Warm-up

Exercise 1 · A design effect

A school-based trial has 30 pupils per school and an ICC of 0.10. Compute the design effect.

Show solution

Step 1. DEFF =1+(m−1)ρ=1+29×0.10=3.9= 1 + (m - 1)\rho = 1 + 29 \times 0.10 = 3.9.

Answer: the variance is 3.9 times that of an individually randomised trial of the same size.

Exercise 2 · Effective sample size

With 60 schools of 30 pupils (Exercise 1), what is the effective sample size?

Show solution

Step 1. Total pupils: 60×30=1,80060 \times 30 = 1{,}800.

Step 2. Effective n=1,800/3.9≈462n = 1{,}800/3.9 \approx 462.

Answer: 1,800 pupils carry the information of about 462 independent ones.

Exercise 3 · SE and MDE

Outcomes are standardised (σ=1\sigma = 1), ρ=0.1\rho = 0.1, m=30m = 30, and 30 schools per arm. Compute the SE and the MDE at 5% significance and 80% power.

Show solution

Step 1. Cluster-mean variance factor: ρ+(1−ρ)/m=0.1+0.9/30=0.13\rho + (1 - \rho)/m = 0.1 + 0.9/30 = 0.13.

Step 2. Var⁡(τ^)=0.13×(1/30+1/30)=0.13×0.0667≈0.00867\operatorname{Var}(\hat\tau) = 0.13 \times (1/30 + 1/30) = 0.13 \times 0.0667 \approx 0.00867; SE ≈0.093\approx 0.093.

Step 3. MDE =2.80×0.093≈0.26= 2.80 \times 0.093 \approx 0.26 sd.

Answer: SE ≈ 0.093 sd; MDE ≈ 0.26 sd.

Exercise 4 · More pupils or more schools?

Starting from Exercise 3, compare (a) doubling pupils per school to 60 and (b) doubling schools to 60 per arm.

Show solution

Step 1. (a) Factor 0.1+0.9/60=0.1150.1 + 0.9/60 = 0.115; variance 0.115×0.0667≈0.007670.115 \times 0.0667 \approx 0.00767; SE ≈0.088\approx 0.088; MDE ≈0.245\approx 0.245.

Step 2. (b) Factor 0.13; variance 0.13×(2/60)≈0.004330.13 \times (2/60) \approx 0.00433; SE ≈0.066\approx 0.066; MDE ≈0.18\approx 0.18.

Answer: both double the sample, but more schools cuts the MDE by 29% versus 6% for more pupils per school.

Exercise 5 · Estimating the ICC

Between-clinic variance of patient satisfaction is 0.2 and within-clinic variance 0.8. Compute the ICC.

Show solution

Step 1. ρ=0.2/(0.2+0.8)=0.2\rho = 0.2/(0.2 + 0.8) = 0.2.

Answer: 0.2: two patients of the same clinic have correlated satisfaction scores.

Part 2 · Proofs

Exercise 6 · Variance of a cluster mean

Under Yig=μ+ug+eigY_{ig} = \mu + u_g + e_{ig} with independent components, prove Var⁡(Yˉg)=σ2[ρ+(1−ρ)/m]\operatorname{Var}(\bar Y_g) = \sigma^2[\rho + (1 - \rho)/m].

Show solution

Step 1. Yˉg=μ+ug+eˉg\bar Y_g = \mu + u_g + \bar e_g, where eˉg\bar e_g averages mm independent errors.

Step 2. Var⁡(Yˉg)=σu2+σe2/m\operatorname{Var}(\bar Y_g) = \sigma_u^2 + \sigma_e^2/m.

Step 3. Substitute σu2=ρσ2\sigma_u^2 = \rho\sigma^2 and σe2=(1−ρ)σ2\sigma_e^2 = (1 - \rho)\sigma^2: σ2[ρ+(1−ρ)/m]\sigma^2[\rho + (1 - \rho)/m]. ■\blacksquare

Exercise 7 · The design effect

Show that σ2[ρ+(1−ρ)/m]=[1+(m−1)ρ] σ2/m\sigma^2[\rho + (1 - \rho)/m] = [1 + (m - 1)\rho]\,\sigma^2/m.

Show solution

Step 1. Factor out σ2/m\sigma^2/m: σ2[ρ+(1−ρ)/m]=σ2m[mρ+1−ρ]\sigma^2[\rho + (1 - \rho)/m] = \frac{\sigma^2}{m}[m\rho + 1 - \rho].

Step 2. mρ+1−ρ=1+(m−1)ρm\rho + 1 - \rho = 1 + (m - 1)\rho. ■\blacksquare

The second form is "individual-level variance σ2/m\sigma^2/m" times the DEFF.

Exercise 8 · The ceiling on cluster size

Prove that as m→∞m \to \infty with J1,J0J_1, J_0 fixed, Var⁡(τ^)→σ2ρ(1/J1+1/J0)\operatorname{Var}(\hat\tau) \to \sigma^2\rho(1/J_1 + 1/J_0).

Show solution

Step 1. (1−ρ)/m→0(1 - \rho)/m \to 0, so the cluster-mean variance tends to ρσ2\rho\sigma^2.

Step 2. Multiply by 1/J1+1/J01/J_1 + 1/J_0. ■\blacksquare

Even infinitely large clusters leave the between-cluster noise: only more clusters remove it.

Exercise 9 · Cluster means analysis

With equal cluster sizes, show that the individual-level difference in means equals the difference in the averages of cluster means. What changes with unequal sizes?

Show solution

Step 1. With mm pupils per cluster, the treated individual mean is 1mJ1∑g∑iYig=1J1∑gYˉg\frac{1}{mJ_1}\sum_g\sum_iY_{ig} = \frac{1}{J_1}\sum_g\bar Y_g, the average of cluster means. The same holds for controls.

Step 2. With unequal sizes, the individual mean weights clusters by size, while the average of cluster means weights them equally.

Answer: they then estimate different estimands: the effect for the average person versus the average cluster. Pre-specify which one you want.

Exercise 10 · Ignoring clustering

Show that an individual-level SE that ignores clustering is too small by the factor DEFF\sqrt{\text{DEFF}} (equal cluster sizes, large samples).

Show solution

Step 1. The naive formula treats all mJmJ observations as independent: σ2(1/(mJ1)+1/(mJ0))\sigma^2(1/(mJ_1) + 1/(mJ_0)).

Step 2. The true variance is DEFF times that (Exercise 7 and the theory block).

Step 3. Ratio of SEs: DEFF\sqrt{\text{DEFF}}. ■\blacksquare

With DEFF = 3.9, naive SEs are about half the correct size and "significant" results can be spurious.

Part 3 · Applied

Exercise 11 · Planning a teacher-training trial

Teacher training is randomised across schools. Pupils' test scores are standardised, m=25m = 25 pupils per school, ICC = 0.15. How many schools are needed for an MDE of 0.20 sd with 5% significance, 80% power and half the schools treated?

Show solution

Step 1. Variance factor: ρ+(1−ρ)/m=0.15+0.85/25=0.184\rho + (1 - \rho)/m = 0.15 + 0.85/25 = 0.184.

Step 2. With P=0.5P = 0.5, P(1−P)J=J/4P(1 - P)J = J/4, so MDE=2.800.184×4/J\text{MDE} = 2.80\sqrt{0.184 \times 4/J}.

Step 3. Set equal to 0.20: (0.20/2.80)2=0.736/J(0.20/2.80)^2 = 0.736/J, i.e. 0.0051=0.736/J0.0051 = 0.736/J.

Step 4. J=0.736/0.0051≈144.3J = 0.736/0.0051 \approx 144.3; round up to an even number.

Answer: about 146 schools (73 per arm), 3,650 pupils.

Exercise 12 · The value of a baseline test

In Exercise 11, school-average baseline scores explain 50% of the between-school variance. If you adjust for them, roughly how many schools are needed?

Show solution

Step 1. Between-school component falls from 0.15 to 0.075; the within-school part stays at 0.85/25 = 0.034 (ignoring individual-level adjustment).

Step 2. New factor: 0.075+0.034=0.1090.075 + 0.034 = 0.109.

Step 3. J=0.109×4/0.0051≈85.5J = 0.109 \times 4/0.0051 \approx 85.5, so about 86 schools.

Answer: about 86 schools instead of 146: a cheap baseline test saves 60 schools.

Exercise 13 · Clinics of different sizes

A trial randomises 40 clinics, from 20 to 500 patients each, to a new hypertension protocol. The protocol may work better in large clinics. Which estimand does a patient-level comparison target, and which does a comparison of clinic means target?

Show solution

Step 1. Patient-level: each patient counts equally, so large clinics dominate: the effect for the average patient.

Step 2. Clinic-level: each clinic counts equally: the effect for the average clinic.

Step 3. If effects differ by size, these differ. A health ministry rolling out across clinics may care about patients; a manager supporting clinics may care about clinics.

Answer: state the estimand in the pre-analysis plan and weight accordingly.

Exercise 14 · Why not randomise individuals?

A village-level information campaign on safe water could instead be randomised by household. Give two reasons to randomise villages.

Show solution

Step 1. Spillovers: households talk to neighbours, so control households in treated villages would be partly treated, biasing the comparison toward zero (Day 32).

Step 2. Delivery: the campaign uses village meetings and posters, which cannot be withheld from some households.

Answer: cluster randomisation trades statistical power for a clean, policy-relevant comparison.

Exercise 15 · Few clusters

A district-level health reform is randomised across 8 districts (4 treated). What inference is appropriate?

Show solution

Step 1. Cluster-robust SEs need many clusters; with 8 they are unreliable (Day 29).

Step 2. Randomisation inference at the district level: (84)=70\binom84 = 70 assignments, smallest two-sided p-value 2/70≈0.0292/70 \approx 0.029 (Day 37).

Step 3. Alternatively, analyse district means with a t-test on 6 degrees of freedom, or the wild cluster bootstrap.

Answer: use district-level randomisation inference, and recognise that only large effects can be detected with 8 districts.

Verify in Python

import numpy as np
from scipy import stats

za, zb = stats.norm.ppf(0.975), stats.norm.ppf(0.80)
def mde(rho, m, J, P=0.5, sigma=1.0):
    return (za + zb) * np.sqrt(sigma**2 * (rho + (1 - rho) / m) / (P * (1 - P) * J))

print("Exercise 3 MDE:", round(mde(0.1, 30, 60), 3))
print("more pupils:", round(mde(0.1, 60, 60), 3), " more schools:", round(mde(0.1, 30, 120), 3))
J = 4 * 0.184 / (0.20 / (za + zb))**2
print("schools needed (Ex 11):", round(J, 1))

# Simulate a cluster RCT: naive versus correct SE
rng = np.random.default_rng(40)
J, m, rho = 60, 30, 0.1
est, naive_se = [], []
for _ in range(3000):
    u = rng.normal(0, np.sqrt(rho), J); T = np.repeat(rng.permutation(np.repeat([0, 1], J // 2)), m)
    y = np.repeat(u, m) + rng.normal(0, np.sqrt(1 - rho), J * m) + 0.0 * T
    est.append(y[T == 1].mean() - y[T == 0].mean())
    naive_se.append(np.sqrt(y[T == 1].var(ddof=1) / (J * m / 2) + y[T == 0].var(ddof=1) / (J * m / 2)))
print(f"true SD {np.std(est):.4f}, mean naive SE {np.mean(naive_se):.4f}, ratio {np.std(est) / np.mean(naive_se):.2f}"
      f" (sqrt DEFF = {np.sqrt(1 + 29 * 0.1):.2f})")

Key takeaways

  • Clustering inflates the variance by DEFF = 1 + (m − 1)ρ; ignoring it makes SEs too small by √DEFF.
  • Power comes mainly from the number of clusters; baseline covariates at the cluster level are very valuable.
  • With unequal cluster sizes, choose the estimand; with few clusters, use cluster-level randomisation inference.

Simulation Lab: Cluster Designs & Power

Open full screen →

Minimum detectable effect against the number of schools for any ICC, cluster size and baseline R².

00.250.50.75150100150200250300number of schools Jminimum detectable effect (sd)
design effect
3.40
1 + (m − 1)ρ
effective pupils per school
7.4
limit 1/ρ = 10.0
schools needed
69
1,725 pupils
schools needed as m → ∞
51
MDE with clusteringif pupils were independenttarget effect

Schools are randomised, pupils are measured. With intraclass correlation ρ, each school of m pupils counts like 1 + (m − 1)ρ fewer pupils. Adding pupils per school hits a ceiling; adding schools does not. Power 80%, two-sided 5%, half the schools treated, outcome in standard deviations.

Day 39Day 41