Math for Causal Inference

Day 44. IPW & Hájek Estimators of the ATE

Re-weighting treated and control units by the inverse of their propensity scores to recreate the population each group is missing.

Video coming soon
Learning outcomes
  • ●Prove the inverse-probability-weighting identities for E[Y(1)], E[Y(0)] and the ATT.
  • ●Compute Horvitz–Thompson and Hájek IPW estimates of the ATE and ATT by hand.
  • ●Diagnose extreme weights with the effective sample size and understand trimming and stabilisation.
  • ●Relate IPW to weighted regression and to survey weighting.
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

The idea

Under unconfoundedness and overlap (Day 42), a treated unit with propensity e(x)e(x) represents 1/e(x)1/e(x) units with the same covariates, some of whom were not treated. Weighting each treated unit by 1/e(X)1/e(X) rebuilds the whole population's Y(1)Y(1) distribution; weighting controls by 1/(1−e(X))1/(1 - e(X)) rebuilds Y(0)Y(0):

E[TYe(X)]=E[Y(1)],E[(1−T)Y1−e(X)]=E[Y(0)].E\Big[\frac{TY}{e(X)}\Big] = E[Y(1)], \qquad E\Big[\frac{(1 - T)Y}{1 - e(X)}\Big] = E[Y(0)].

(This is Day 14's missing-data result applied twice.)

Estimators

Horvitz–Thompson (HT):

τ^HT=1n∑iTiYie^(Xi)−1n∑i(1−Ti)Yi1−e^(Xi).\hat\tau_{HT} = \frac1n\sum_i\frac{T_iY_i}{\hat e(X_i)} - \frac1n\sum_i\frac{(1 - T_i)Y_i}{1 - \hat e(X_i)}.

Hájek (normalised): divide each weighted sum by the sum of its weights instead of nn:

τ^H=∑iTiYi/e^i∑iTi/e^i−∑i(1−Ti)Yi/(1−e^i)∑i(1−Ti)/(1−e^i).\hat\tau_{H} = \frac{\sum_iT_iY_i/\hat e_i}{\sum_iT_i/\hat e_i} - \frac{\sum_i(1 - T_i)Y_i/(1 - \hat e_i)}{\sum_i(1 - T_i)/(1 - \hat e_i)}.

Hájek is invariant to shifting YY by a constant, keeps each mean within the range of the data, and usually has lower variance. It equals a weighted regression of YY on TT (Day 24).

ATT: treated units get weight 1; controls get e^/(1−e^)\hat e/(1 - \hat e) (the odds of treatment), which reshapes the controls to look like the treated.

Weights and precision

When e^\hat e is near 0 or 1, a few units get huge weights and dominate the estimate. Diagnostics and remedies:

  • Effective sample size: ESS=(∑wi)2/∑wi2\text{ESS} = (\sum w_i)^2/\sum w_i^2, the number of equally weighted units with the same precision.
  • Trimming units with extreme e^\hat e (changes the estimand, Day 42) or truncating weights at a cap (adds a little bias).
  • Using the estimated propensity score is, perhaps surprisingly, more efficient than using the true one (Hirano, Imbens & Ridder 2003).

Part 1 · Warm-up

Exercise 1 · Individual weights

A treated household has e=0.25e = 0.25 and a control household also has e=0.25e = 0.25. What ATE weights do they get, and what do the weights mean?

Show solution

Step 1. Treated: 1/0.25=41/0.25 = 4. It stands in for itself and three similar households that were not treated.

Step 2. Control: 1/(1−0.25)≈1.331/(1 - 0.25) \approx 1.33. Controls with this profile are common, so each represents only a third more households.

Exercise 2 · An ATT weight

What ATT weight does the control household in Exercise 1 get?

Show solution

Step 1. Odds of treatment: e/(1−e)=0.25/0.75=1/3e/(1 - e) = 0.25/0.75 = 1/3.

Answer: 1/3. Profiles that are rarely treated get small weight when we want controls to resemble the treated.

Exercise 3 · Effective sample size

Four units have weights 1, 1, 1 and 10. Compute the ESS.

Show solution

Step 1. ∑w=13\sum w = 13 and ∑w2=1+1+1+100=103\sum w^2 = 1 + 1 + 1 + 100 = 103.

Step 2. ESS =132/103≈1.64= 13^2/103 \approx 1.64.

Answer: four units carry the information of fewer than two: one unit dominates.

Exercise 4 · Hájek is location-invariant

Add 100 to every outcome. How do the HT and Hájek estimates of E[Y(1)]E[Y(1)] change?

Show solution

Step 1. Hájek: weighted average of Y+100Y + 100 is the old weighted average plus 100 (weights sum to one after normalising).

Step 2. HT: adds 100×1n∑iTi/e^i100 \times \frac1n\sum_iT_i/\hat e_i, which equals 100 only if the sample weights average exactly to 1.

Answer: Hájek shifts by exactly 100; HT shifts by 100 times a random factor, so it is not location-invariant.

Exercise 5 · Truncation

Weights above 20 are capped at 20. Which quantity does this change, and what is the trade-off?

Show solution

Step 1. The weighted means no longer exactly reproduce the population, so a small bias appears.

Step 2. Variance falls, often a lot.

Answer: a bias–variance trade-off (Day 8); report results with and without truncation.

Part 2 · Proofs

Exercise 6 · The IPW identity

Under unconfoundedness and e(X)>0e(X) > 0, prove E[TY/e(X)]=E[Y(1)]E[TY/e(X)] = E[Y(1)].

Show solution

Step 1. TY=TY(1)TY = TY(1) (the observed outcome of treated units).

Step 2. LIE: E[TY(1)e(X)]=E[E[TY(1)∣X]e(X)]E\Big[\frac{TY(1)}{e(X)}\Big] = E\Big[\frac{E[TY(1) \mid X]}{e(X)}\Big].

Step 3. Unconfoundedness: E[TY(1)∣X]=E[T∣X] E[Y(1)∣X]=e(X) E[Y(1)∣X]E[TY(1) \mid X] = E[T \mid X]\,E[Y(1) \mid X] = e(X)\,E[Y(1) \mid X].

Step 4. The e(X)e(X) cancels: E[E[Y(1)∣X]]=E[Y(1)]E\big[E[Y(1) \mid X]\big] = E[Y(1)]. ■\blacksquare

Exercise 7 · ATT weights

Under Y(0)⊥T∣XY(0) \perp T \mid X and e(X)<1e(X) < 1, prove E[(1−T)e(X)1−e(X)Y]=P(T=1) E[Y(0)∣T=1]E\Big[\frac{(1 - T)e(X)}{1 - e(X)}Y\Big] = P(T = 1)\,E[Y(0) \mid T = 1].

Show solution

Step 1. (1−T)Y=(1−T)Y(0)(1 - T)Y = (1 - T)Y(0).

Step 2. LIE and unconfoundedness: E[(1−T)Y(0)∣X]=(1−e(X))E[Y(0)∣X]E[(1 - T)Y(0) \mid X] = (1 - e(X))E[Y(0) \mid X].

Step 3. So the expectation equals E[e(X)E[Y(0)∣X]]E\big[e(X)E[Y(0) \mid X]\big].

Step 4. Also P(T=1)E[Y(0)∣T=1]=E[TY(0)]=E[E[T∣X]E[Y(0)∣X]]=E[e(X)E[Y(0)∣X]]P(T = 1)E[Y(0) \mid T = 1] = E[TY(0)] = E\big[E[T \mid X]E[Y(0) \mid X]\big] = E\big[e(X)E[Y(0) \mid X]\big] (unconfoundedness again). The two agree. ■\blacksquare

Dividing by P(T=1)P(T = 1) (or normalising the weights) gives E[Y(0)∣T=1]E[Y(0) \mid T = 1].

Exercise 8 · Hájek is weighted least squares

Show that regressing YY on an intercept and TT with weights wi=Ti/e^i+(1−Ti)/(1−e^i)w_i = T_i/\hat e_i + (1 - T_i)/(1 - \hat e_i) gives the Hájek estimator.

Show solution

Step 1. WLS with columns (1,T)(1, T) fits a separate weighted mean in each arm (Day 24, Exercise 12).

Step 2. The treated arm's weighted mean is ∑TiYi/e^i/∑Ti/e^i\sum T_iY_i/\hat e_i\big/\sum T_i/\hat e_i; the control arm's is the analogous expression with 1/(1−e^i)1/(1 - \hat e_i).

Step 3. The slope on TT is their difference: τ^H\hat\tau_H. ■\blacksquare

In practice, use robust SEs that account for estimating e^\hat e (or bootstrap the whole procedure).

Exercise 9 · Why HT is less stable

Show that the HT estimate of E[Y(1)]E[Y(1)] can be written as μ^H⋅1n∑iTi/e^i\hat\mu_{H}\cdot\frac1n\sum_iT_i/\hat e_i, where μ^H\hat\mu_H is the Hájek mean, and explain the consequence.

Show solution

Step 1. By definition, μ^H=∑iTiYi/e^i/∑iTi/e^i\hat\mu_H = \sum_iT_iY_i/\hat e_i\big/\sum_iT_i/\hat e_i.

Step 2. Multiply both sides by 1n∑iTi/e^i\frac1n\sum_iT_i/\hat e_i: 1n∑iTiYi/e^i\frac1n\sum_iT_iY_i/\hat e_i, the HT mean.

Step 3. The factor has expectation 1 but varies from sample to sample, especially with extreme weights.

Answer: HT multiplies the Hájek mean by a noisy factor, adding variance proportional to the level of YY.

Exercise 10 · Weights that explode

Show that Var⁡(TY/e(X))\operatorname{Var}(TY/e(X)) involves E[Y(1)2/e(X)]E[Y(1)^2/e(X)], and explain why limited overlap can make IPW very imprecise.

Show solution

Step 1. E[(TY/e)2]=E[TY(1)2/e2]=E[E[T∣X]E[Y(1)2∣X]/e(X)2]=E[Y(1)2/e(X)]E[(TY/e)^2] = E[TY(1)^2/e^2] = E\big[E[T \mid X]E[Y(1)^2 \mid X]/e(X)^2\big] = E[Y(1)^2/e(X)].

Step 2. If e(X)e(X) is close to 0 for a non-negligible share of units, this expectation is huge (or infinite if ee can be arbitrarily close to 0).

Answer: IPW variance is driven by the smallest propensities; poor overlap means imprecise IPW, which is why diagnostics come first.

Part 3 · Applied

Six households in a cash-transfer evaluation, with estimated propensities e^\hat e and monthly savings YY ($10):

HouseholdTTe^\hat eYY
110.820
210.516
310.210
400.814
500.512
600.28

Exercise 11 · Naive and Horvitz–Thompson

Compute the naive difference in means and the HT estimate of the ATE.

Show solution

Step 1. Naive: treated mean (20+16+10)/3≈15.33(20 + 16 + 10)/3 \approx 15.33; control mean (14+12+8)/3≈11.33(14 + 12 + 8)/3 \approx 11.33; difference 4.0.

Step 2. HT for Y(1)Y(1): 16(20/0.8+16/0.5+10/0.2)=16(25+32+50)=107/6≈17.83\frac16(20/0.8 + 16/0.5 + 10/0.2) = \frac16(25 + 32 + 50) = 107/6 \approx 17.83.

Step 3. HT for Y(0)Y(0): 16(14/0.2+12/0.5+8/0.8)=16(70+24+10)=104/6≈17.33\frac16(14/0.2 + 12/0.5 + 8/0.8) = \frac16(70 + 24 + 10) = 104/6 \approx 17.33.

Step 4. τ^HT=17.83−17.33=0.50\hat\tau_{HT} = 17.83 - 17.33 = 0.50.

Answer: naive 4.0 versus HT 0.5. The treated have higher propensities (likely better-off households), and weighting removes most of the gap.

Exercise 12 · Hájek

Compute the Hájek estimate of the ATE for the same households.

Show solution

Step 1. Treated weights 1/e^1/\hat e: 1.25, 2, 5 (sum 8.25). Weighted mean: (25+32+50)/8.25=107/8.25≈12.97(25 + 32 + 50)/8.25 = 107/8.25 \approx 12.97.

Step 2. Control weights 1/(1−e^)1/(1 - \hat e): 5, 2, 1.25 (sum 8.25). Weighted mean: 104/8.25≈12.61104/8.25 \approx 12.61.

Step 3. τ^H=12.97−12.61≈0.36\hat\tau_H = 12.97 - 12.61 \approx 0.36.

Answer: 0.36. With six units HT and Hájek differ noticeably; Hájek's means (≈ 13) stay within the range of the data, whereas HT's (≈ 17.8) do not.

Exercise 13 · The ATT

Compute the IPW estimate of the ATT.

Show solution

Step 1. Treated mean (weight 1 each): 15.33.

Step 2. Control ATT weights e^/(1−e^)\hat e/(1 - \hat e): household 4: 0.8/0.2=40.8/0.2 = 4; household 5: 1; household 6: 0.2/0.8=0.250.2/0.8 = 0.25 (sum 5.25).

Step 3. Weighted control mean: (4×14+1×12+0.25×8)/5.25=(56+12+2)/5.25=70/5.25≈13.33(4 \times 14 + 1 \times 12 + 0.25 \times 8)/5.25 = (56 + 12 + 2)/5.25 = 70/5.25 \approx 13.33.

Step 4. ATT ≈15.33−13.33=2.0\approx 15.33 - 13.33 = 2.0.

Answer: 2.0 ($20/month). Controls that look like the treated (high e^\hat e) get most of the weight.

Exercise 14 · Extreme weights in a hospital study

In a study of a surgical procedure, one untreated patient has e^=0.99\hat e = 0.99 and gets an ATE weight of 100; the next largest weight is 8. The estimate changes from a 3-point to a 9-point mortality reduction when this patient is dropped. What should be reported?

Show solution

Step 1. A single patient driving the estimate signals an overlap problem: almost everyone like this patient is treated.

Step 2. Report the ESS, the weight distribution and estimates with trimming (e.g. e^∈[0.05,0.95]\hat e \in [0.05, 0.95]) or truncation.

Step 3. Consider a doubly robust estimator (Day 45), which leans on an outcome model where weights are extreme and is less sensitive to a single large weight.

Answer: do not report a single IPW number; show its sensitivity to the extreme weight and redefine the estimand for the overlap population if needed.

Exercise 15 · Survey weights and IPW

National surveys oversample poor regions and publish weights equal to the inverse of each household's sampling probability. Explain the parallel with IPW and why both rely on knowing (or estimating well) a probability.

Show solution

Step 1. Survey sampling: each sampled household represents 1/πi1/\pi_i households in the population; weighting by 1/πi1/\pi_i gives unbiased population means (Horvitz & Thompson, 1952).

Step 2. IPW: each treated unit "was sampled" into treatment with probability e(Xi)e(X_i), so weighting by 1/e(Xi)1/e(X_i) recovers the population mean of Y(1)Y(1).

Step 3. Survey designers know πi\pi_i; observational analysts must estimate e(X)e(X) and assume no unobserved confounding.

Answer: the same estimator; the difference is whether the selection probability is known by design or estimated under assumptions.

Verify in Python

import numpy as np
from scipy import optimize

T = np.array([1, 1, 1, 0, 0, 0]); e = np.array([.8, .5, .2, .8, .5, .2]); Y = np.array([20, 16, 10, 14, 12, 8.])
ht = (T * Y / e).mean() - ((1 - T) * Y / (1 - e)).mean()
hj = (T * Y / e).sum() / (T / e).sum() - ((1 - T) * Y / (1 - e)).sum() / ((1 - T) / (1 - e)).sum()
w = e / (1 - e); c = T == 0
print(f"naive {Y[T == 1].mean() - Y[T == 0].mean():.2f}, HT {ht:.2f}, Hajek {hj:.2f}, "
      f"ATT {Y[T == 1].mean() - (w[c] * Y[c]).sum() / w[c].sum():.2f}")

# Monte Carlo: HT vs Hajek, true vs estimated propensity scores
rng = np.random.default_rng(44)
res = {"HT": [], "Hajek": [], "Hajek (true e)": []}
for _ in range(2000):
    n = 500; x = rng.normal(size=n); X = np.column_stack([np.ones(n), x])
    e_true = 1 / (1 + np.exp(-1.2 * x)); T = rng.random(n) < e_true
    y = 50 + 5 * x + 2 * T + rng.normal(0, 3, n)
    b = optimize.minimize(lambda b: -np.sum(T * (X @ b) - np.log1p(np.exp(X @ b))), np.zeros(2)).x
    eh = 1 / (1 + np.exp(-X @ b))
    res["HT"].append((T * y / eh).mean() - ((1 - T) * y / (1 - eh)).mean())
    for key, ee in (("Hajek", eh), ("Hajek (true e)", e_true)):
        res[key].append((T * y / ee).sum() / (T / ee).sum() - ((1 - T) * y / (1 - ee)).sum() / ((1 - T) / (1 - ee)).sum())
for k, v in res.items():
    print(f"{k:15s} mean {np.mean(v):.3f} (truth 2)  SD {np.std(v):.3f}")

Key takeaways

  • Weighting by 1/e and 1/(1 − e) recreates the population's Y(1) and Y(0) under unconfoundedness and overlap.
  • Prefer the normalised (Hájek) estimator; use odds weights for the ATT.
  • Extreme weights signal poor overlap: check the ESS and report sensitivity to trimming.

Simulation Lab: Horvitz–Thompson vs Hájek

Open full screen →

Monte Carlo of two IPW estimators; shift the outcome level and only the normalised (Hájek) version stays stable.

-10123estimated ATE, 1,200 samples
Horvitz–Thompson
sd 3.497
bias -0.132
Hájek
sd 0.485
bias 0.049
effective sample size
167
of n = 300
sd ratio HT ÷ Hájek
7.20
Horvitz–ThompsonHájek (normalised weights)

Weighting by 1/e(x) recreates a randomised comparison. Horvitz–Thompson divides by n; Hájek divides by the sum of the weights, so adding a constant to every outcome cannot move it. Raise the outcome level and watch HT spread out while Hájek stays put. True effect +1.

Day 43Day 45