Math for Causal Inference

Day 35. Randomisation & Identification

How random assignment makes treatment independent of everything that came before, what balance tables can and cannot tell you, and internal versus external validity.

Video coming soon
Learning outcomes
  • ●Describe Bernoulli, complete, stratified and cluster randomisation and compute their basic probabilities.
  • ●Prove that random assignment identifies the ATE and balances covariates in expectation.
  • ●Interpret balance tests and chance imbalance correctly.
  • ●Distinguish internal validity (randomisation) from external validity (random sampling).
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

Assignment mechanisms

DesignRuleNumber treated
Bernoullieach unit independently with probability pprandom
Completeexactly n1n_1 of nn, all (nn1)\binom{n}{n_1} sets equally likelyfixed
Stratified (blocked)complete randomisation within blocksfixed per block (Day 38)
Clusterwhole groups assigned togetherDay 40

All share three properties (Imbens & Rubin 2015): individualistic (probabilities do not depend on other units' outcomes), probabilistic (0<P(Ti=1)<10 < P(T_i = 1) < 1) and unconfounded (assignment does not depend on potential outcomes).

Why randomisation identifies the ATE

Random assignment makes TT independent of (Y(0),Y(1),X)(Y(0), Y(1), X), all of which are fixed before assignment. Hence

E[Y∣T=1]−E[Y∣T=0]=E[Y(1)]−E[Y(0)]=ATE.E[Y \mid T = 1] - E[Y \mid T = 0] = E[Y(1)] - E[Y(0)] = \text{ATE}.

Selection bias and heterogeneity bias (Day 34) are zero by design. This is identification without any model of outcomes.

Balance

Independence implies balance in expectation: the treated and control groups have the same covariate distribution on average across randomisations. In any one experiment, chance imbalances occur. A balance table is a check that randomisation was implemented, not a test of whether it "worked": with 20 covariates, about one will differ "significantly" at 5% by chance alone. Large chance imbalance in a strong predictor of the outcome is best handled by design (blocking, Day 38) or pre-specified adjustment (Day 39).

Internal and external validity

  • Internal validity: the estimate is causal for the units studied. Random assignment delivers it.
  • External validity: the estimate applies to other populations, places or scales. Random sampling from the target population helps; random assignment does not.

Part 1 · Warm-up

Exercise 1 · Bernoulli surprises

Ten clinics are each assigned to a new protocol by a fair coin flip. What is the probability that none is treated?

Show solution

Step 1. Each clinic is untreated with probability 0.5, independently.

Step 2. 0.510=1/1024≈0.0010.5^{10} = 1/1024 \approx 0.001.

Answer: about 0.1%; small, but Bernoulli designs can produce lopsided splits, which complete randomisation rules out.

Exercise 2 · Counting complete randomisations

A study randomises 10 of 20 schools to a reading programme. How many assignments are possible?

Show solution

Step 1. (2010)=20!10! 10!=184,756\binom{20}{10} = \frac{20!}{10!\,10!} = 184{,}756.

Answer: 184,756 equally likely assignments.

Exercise 3 · How many get treated?

200 farmers are each offered a subsidy with probability 0.3 (Bernoulli). Find the mean and sd of the number offered.

Show solution

Step 1. Number offered ∼\sim Binomial(200, 0.3): mean 200×0.3=60200 \times 0.3 = 60.

Step 2. sd =200×0.3×0.7=42≈6.5= \sqrt{200 \times 0.3 \times 0.7} = \sqrt{42} \approx 6.5.

Answer: about 60 ± 6.5.

Exercise 4 · Balance tests by chance

A balance table compares treatment and control on 20 independent baseline covariates at the 5% level. How many "significant" differences should you expect, and what is the chance of at least one?

Show solution

Step 1. Expected number: 20×0.05=120 \times 0.05 = 1.

Step 2. At least one: 1−0.9520≈0.641 - 0.95^{20} \approx 0.64.

Answer: one, and a 64% chance of at least one, even with perfect randomisation.

Exercise 5 · Lotteries

300 families apply for 100 places in an oversubscribed charter school, allocated by lottery. What is each applicant's probability of admission, and who is the study population?

Show solution

Step 1. P(win)=100/300=1/3P(\text{win}) = 100/300 = 1/3 for every applicant.

Step 2. The comparison is winners versus losers among applicants.

Answer: 1/3. The lottery identifies the effect for families who apply, who may differ from non-applicants (external validity).

Part 2 · Proofs

Exercise 6 · Randomisation identifies the ATE

Prove that if TT is independent of (Y(0),Y(1))(Y(0), Y(1)) and 0<P(T=1)<10 < P(T = 1) < 1, then E[Y∣T=1]−E[Y∣T=0]=ATEE[Y \mid T = 1] - E[Y \mid T = 0] = \text{ATE}.

Show solution

Step 1. E[Y∣T=1]=E[Y(1)∣T=1]E[Y \mid T = 1] = E[Y(1) \mid T = 1] (observed outcome of the treated).

Step 2. Independence: E[Y(1)∣T=1]=E[Y(1)]E[Y(1) \mid T = 1] = E[Y(1)].

Step 3. Likewise E[Y∣T=0]=E[Y(0)∣T=0]=E[Y(0)]E[Y \mid T = 0] = E[Y(0) \mid T = 0] = E[Y(0)]. (0<P(T=1)<10 < P(T = 1) < 1 makes both conditional means defined.)

Step 4. Difference: E[Y(1)]−E[Y(0)]=ATEE[Y(1)] - E[Y(0)] = \text{ATE}. ■\blacksquare

Exercise 7 · Dependence in complete randomisation

With n1n_1 of nn treated completely at random, find P(Ti=1)P(T_i = 1), P(Ti=1,Tj=1)P(T_i = 1, T_j = 1) for i≠ji \ne j, and Cov⁡(Ti,Tj)\operatorname{Cov}(T_i, T_j).

Show solution

Step 1. By symmetry each unit is equally likely to be among the n1n_1: P(Ti=1)=n1/nP(T_i = 1) = n_1/n.

Step 2. Given ii is treated, n1−1n_1 - 1 of the remaining n−1n - 1 slots are treated: P(Ti=1,Tj=1)=n1n⋅n1−1n−1P(T_i = 1, T_j = 1) = \frac{n_1}{n}\cdot\frac{n_1 - 1}{n - 1}.

Step 3. Cov⁡=n1(n1−1)n(n−1)−n12n2=n1n(n1−1n−1−n1n)=−n1n0n2(n−1)\operatorname{Cov} = \frac{n_1(n_1 - 1)}{n(n - 1)} - \frac{n_1^2}{n^2} = \frac{n_1}{n}\Big(\frac{n_1 - 1}{n - 1} - \frac{n_1}{n}\Big) = -\frac{n_1n_0}{n^2(n - 1)}.

Answer: slightly negative covariance (Day 1, Exercise 15); it drives the finite-population variance of Day 36.

Exercise 8 · Balance in expectation

Under complete randomisation, prove E[Xˉ1−Xˉ0]=0E[\bar X_1 - \bar X_0] = 0 for any fixed covariate XX.

Show solution

Step 1. Xˉ1=1n1∑iTiXi\bar X_1 = \frac{1}{n_1}\sum_iT_iX_i, so E[Xˉ1]=1n1∑in1nXi=XˉE[\bar X_1] = \frac{1}{n_1}\sum_i\frac{n_1}{n}X_i = \bar X.

Step 2. Likewise E[Xˉ0]=XˉE[\bar X_0] = \bar X.

Step 3. Difference: 0. ■\blacksquare

Covariates behave like potential outcomes that treatment cannot change (Day 31, Exercise 8 with Y(1)=Y(0)=XY(1) = Y(0) = X).

Exercise 9 · Unbiased on average, not in every draw

Suppose Yi(0)=Xi+εiY_i(0) = X_i + \varepsilon_i and the effect is constant, τ\tau. Show that, conditional on the realised assignment, Yˉ1−Yˉ0=τ+(Xˉ1−Xˉ0)+(εˉ1−εˉ0)\bar Y_1 - \bar Y_0 = \tau + (\bar X_1 - \bar X_0) + (\bar\varepsilon_1 - \bar\varepsilon_0). What does this imply when you observe a large baseline imbalance?

Show solution

Step 1. Treated outcomes: Yi=Xi+εi+τY_i = X_i + \varepsilon_i + \tau; control outcomes: Yi=Xi+εiY_i = X_i + \varepsilon_i.

Step 2. Average within each group and subtract: τ+(Xˉ1−Xˉ0)+(εˉ1−εˉ0)\tau + (\bar X_1 - \bar X_0) + (\bar\varepsilon_1 - \bar\varepsilon_0).

Step 3. Across randomisations the imbalance terms average to zero (Exercise 8), so the estimator is unbiased.

Step 4. But in this experiment, if Xˉ1−Xˉ0\bar X_1 - \bar X_0 is large, the estimate is shifted by it.

Answer: a large observed imbalance in a predictive covariate tells you this particular estimate is likely off; adjusting for XX (Day 39) or blocking on it in advance (Day 38) fixes this.

Exercise 10 · Unequal probabilities

Pupils in poor districts are treated with probability 0.8 and others with 0.2. Explain why a simple difference in means is biased for the ATE and how weighting by 1/P(Ti=t)1/P(T_i = t) fixes it.

Show solution

Step 1. The treated group over-represents poor districts (80% vs 20% treated), so if Y(0)Y(0) differs by district, the comparison mixes in district differences: selection bias by design.

Step 2. Within each district, assignment is random, so district-specific differences are unbiased.

Step 3. Weighting each unit by the inverse of its probability of the treatment it got re-creates the population in both arms: E[TY/e]=E[Y(1)]E[TY/e] = E[Y(1)] and E[(1−T)Y/(1−e)]=E[Y(0)]E[(1 - T)Y/(1 - e)] = E[Y(0)] (Day 14).

Answer: use IPW (or estimate by district and average with population shares). Known probabilities make this exact; Day 44 handles estimated ones.

Part 3 · Applied

Exercise 11 · A charter-school lottery

Among applicants, lottery winners score 0.25 sd higher in maths than losers two years later (SE 0.08). All winners enrol and no losers do. Interpret the estimate and its CI.

Show solution

Step 1. The lottery makes winning independent of potential scores, so 0.25 is an unbiased estimate of the ATE of charter attendance for applicants.

Step 2. 95% CI: 0.25±1.96×0.08=[0.09,  0.41]0.25 \pm 1.96 \times 0.08 = [0.09,\; 0.41].

Answer: attending raised maths scores by about a quarter of a standard deviation (plausibly 0.1–0.4) for families who applied; whether it would do so for non-applicants is an external-validity question.

Exercise 12 · A vaccine trial

30,000 adults are randomised 2:1 to vaccine or placebo. There are 11 infections among 20,000 vaccinated and 185 among 10,000 on placebo. Compute the infection risks, the risk difference and vaccine efficacy.

Show solution

Step 1. Risks: vaccine 11/20,000=0.0005511/20{,}000 = 0.00055; placebo 185/10,000=0.0185185/10{,}000 = 0.0185.

Step 2. Risk difference =0.00055−0.0185≈−0.018= 0.00055 - 0.0185 \approx -0.018 (18 fewer infections per 1,000).

Step 3. Efficacy =1−0.00055/0.0185≈1−0.030=0.97= 1 - 0.00055/0.0185 \approx 1 - 0.030 = 0.97.

Answer: 97% efficacy. Randomisation means the arms differ only by vaccine (and chance), so the comparison is causal.

Exercise 13 · Microcredit in one city

An RCT finds that offering microloans in one large city raised business investment by 20%. A ministry plans a national roll-out to rural areas. What does randomisation guarantee, and what does it not?

Show solution

Step 1. Internal validity: within the study city, the 20% is causal for the households studied.

Step 2. External validity is not guaranteed: rural households differ in business opportunities, market access and existing credit.

Step 3. Scale effects matter too: a national programme can change interest rates or local demand (SUTVA, Day 32).

Answer: randomisation guarantees the first; the roll-out needs evidence from more sites, a model of heterogeneity (CATEs, Day 33) or a pilot in rural areas.

Exercise 14 · An unlucky balance table

In a job-training RCT, treated workers earned $500 more at baseline than controls (SE $400). The follow-up difference in earnings is $1,200. What should the analyst do?

Show solution

Step 1. The baseline difference has z=500/400=1.25z = 500/400 = 1.25: consistent with chance, so no evidence that randomisation failed.

Step 2. But baseline earnings strongly predict follow-up earnings, so part of the $1,200 may reflect the imbalance (Exercise 9).

Step 3. Report the pre-specified covariate-adjusted estimate (Day 39) alongside the raw difference; do not drop or re-weight units ad hoc.

Answer: keep the experiment, adjust for baseline earnings, and report both estimates.

Exercise 15 · Randomisation as the basis for inference

Fisher argued that randomisation provides "the reasoned basis" for inference. In a study of 8 villages with 4 treated, how many assignments could have happened, and what probability statement does this enable without any model of outcomes?

Show solution

Step 1. (84)=70\binom84 = 70 equally likely assignments.

Step 2. Under the sharp null of no effect for any village, every outcome is known whatever the assignment, so we can compute the test statistic for all 70.

Step 3. The p-value is the share of the 70 assignments giving a statistic at least as extreme as the one observed.

Answer: 70 assignments; randomisation alone yields an exact p-value (Day 37).

Verify in Python

import numpy as np
from math import comb

print("assignments C(20,10):", comb(20, 10))
print("P(none treated) with 10 coin flips:", 0.5**10)

# Balance in expectation and chance imbalance across randomisations
rng = np.random.default_rng(35)
n, n1 = 100, 50
X = rng.lognormal(10, 0.5, n)                       # baseline earnings, fixed
y0 = X / 1000 + rng.normal(0, 3, n); y1 = y0 + 2    # constant effect of 2
diffs, ests = [], []
for _ in range(20_000):
    T = np.zeros(n, bool); T[rng.choice(n, n1, replace=False)] = True
    diffs.append(X[T].mean() - X[~T].mean())
    ests.append(y1[T].mean() - y0[~T].mean())
diffs, ests = np.array(diffs), np.array(ests)
print(f"baseline imbalance: mean {diffs.mean():.0f}, sd {diffs.std():.0f} (mean ~0 relative to sd); mean estimate {ests.mean():.3f} (truth 2)")
print("corr(imbalance, estimate):", round(np.corrcoef(diffs, ests)[0, 1], 2))

# Vaccine trial (Exercise 12)
r1, r0 = 11 / 20_000, 185 / 10_000
print(f"risks {r1:.5f} vs {r0:.4f}; efficacy {1 - r1 / r0:.3f}")

Key takeaways

  • Random assignment makes treatment independent of potential outcomes and covariates, so the difference in means identifies the ATE.
  • Balance holds in expectation; chance imbalance in any one experiment is handled by blocking or pre-specified adjustment.
  • Randomisation buys internal validity; external validity needs more.

Simulation Lab: Randomisation Balances Covariates

Open full screen →

Thousands of re-assignments: baseline imbalance and estimates under complete, Bernoulli and self-selected assignment.

BASELINE IMBALANCE IN EARNINGS (treated − control)
-10-50510
ESTIMATED EFFECT (truth = 2)
-50510
mean imbalance
-0.02
mean estimate
1.98
truth 2
sd of estimates
2.01

2,000 re-assignments of the same workers. True effect 2. Under randomisation the baseline imbalance and the estimates centre on 0 and 2; under self-selection (low earners enrol more) both shift. Each single experiment still has some chance imbalance.

Day 34Day 36