Math for Causal Inference

Day 59. Counterfactuals & the Ladder of Causation

The top rung: what would have happened to this unit, given what actually happened? Abduction, action and prediction compute counterfactuals from an SCM; probabilities of necessity and sufficiency answer attribution questions, and are only partly identified from data.

Video coming soon
Learning outcomes
  • ●Place a question on the ladder of causation (association, intervention, counterfactual).
  • ●Compute unit-level counterfactuals with abduction, action and prediction.
  • ●Derive and apply the probability of necessity under exogeneity and monotonicity, and bounds on the probability of necessity and sufficiency.
  • ●Show that two models can agree on every experiment and still disagree on counterfactuals.
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 ladder of causation

RungQuestionNotationNeeds
1. AssociationWhat do I expect to see if I observe xx?P(y∣x)P(y \mid x)data
2. InterventionWhat happens if I do xx?P(y∣do⁡(x))P(y \mid \operatorname{do}(x))data + causal graph (or an experiment)
3. CounterfactualGiven that xx and yy happened, what would yy have been under x′x'?P(yx′∣x,y)P(y_{x'} \mid x, y)an SCM (functions, not only a graph)

Each rung needs more assumptions than the one below.

Counterfactuals in an SCM

For unit uu (a value of the disturbances U\mathbf U), the counterfactual Yx(u)Y_x(u) is the value of YY in the modified model Mx\mathcal M_x. These are Phase 3's potential outcomes, now derived from structural equations. Consistency: if X(u)=xX(u) = x then Yx(u)=Y(u)Y_x(u) = Y(u).

Three steps

To compute P(yx′∣evidence e)P(y_{x'} \mid \text{evidence } e):

  1. Abduction: update the disturbances using the evidence: P(u)→P(u∣e)P(\mathbf u) \to P(\mathbf u \mid e).
  2. Action: replace XX's equation by X:=x′X := x'.
  3. Prediction: compute YY in the modified model, using P(u∣e)P(\mathbf u \mid e).

Linear models: the same effect for everyone

If Y:=βX+UYY := \beta X + U_Y (whatever the dependence between XX and UYU_Y), then Yx′(u)−Yx(u)=β(x′−x)Y_{x'}(u) - Y_x(u) = \beta(x' - x) for every unit. Unit-level counterfactuals are easy; they are hard precisely when effects vary across units.

Attribution: necessity and sufficiency

For binary X,YX, Y (write yy for Y=1Y = 1, y′y' for Y=0Y = 0):

  • Probability of necessity: PN=P(Y0=0∣X=1,Y=1)PN = P(Y_0 = 0 \mid X = 1, Y = 1): among exposed people who got the disease, the share who would not have without exposure ("but-for" causation in law).
  • Probability of sufficiency: PS=P(Y1=1∣X=0,Y=0)PS = P(Y_1 = 1 \mid X = 0, Y = 0).
  • Probability of necessity and sufficiency: PNS=P(Y1=1,Y0=0)PNS = P(Y_1 = 1, Y_0 = 0): the share of units who respond.

Identification under extra assumptions

If XX is exogenous (randomised) and the effect is monotone (no one is harmed: Y1≥Y0Y_1 \ge Y_0), then

PN=P(y∣x)−P(y∣x′)P(y∣x)=1−1RR,PNS=P(y∣x)−P(y∣x′).PN = \frac{P(y \mid x) - P(y \mid x')}{P(y \mid x)} = 1 - \frac{1}{RR}, \qquad PNS = P(y \mid x) - P(y \mid x').

Without monotonicity, experiments give only bounds, for example

max⁡{0,  P(yx)−P(yx′)}≤PNS≤min⁡{P(yx),  P(yx′′)}.\max\{0,\; P(y_x) - P(y_{x'})\} \le PNS \le \min\{P(y_x),\; P(y'_{x'})\}.

Part 1 · Warm-up

Exercise 1 · Which rung?

Classify: (a) "Patients who take aspirin have fewer heart attacks." (b) "If we give everyone aspirin, heart attacks will fall by 10%." (c) "Would Mr Lee have avoided his heart attack if he had taken aspirin?" (d) "What share of heart attacks among non-users would aspirin have prevented?"

Show solution

Step 1. (a) Rung 1 (association).

Step 2. (b) Rung 2 (intervention).

Step 3. (c) Rung 3: a counterfactual about a specific person, given what happened.

Step 4. (d) Rung 3: a counterfactual conditioned on observed status (non-users who had attacks).

Exercise 2 · Abduction, action, prediction

Y:=2X+UYY := 2X + U_Y. A unit has X=3X = 3, Y=7Y = 7. What would YY have been with X=5X = 5?

Show solution

Step 1. Abduction: UY=Y−2X=7−6=1U_Y = Y - 2X = 7 - 6 = 1.

Step 2. Action: set X:=5X := 5.

Step 3. Prediction: Y5=2(5)+1=11Y_5 = 2(5) + 1 = 11.

Exercise 3 · Counterfactuals downstream

X:=UXX := U_X, M:=0.5X+UMM := 0.5X + U_M, Y:=M+X+UYY := M + X + U_Y. A unit has X=2X = 2, M=1.5M = 1.5, Y=4Y = 4. Compute YX=0Y_{X = 0} and MX=0M_{X = 0}.

Show solution

Step 1. Abduction: UM=1.5−1=0.5U_M = 1.5 - 1 = 0.5; UY=4−1.5−2=0.5U_Y = 4 - 1.5 - 2 = 0.5.

Step 2. Action: X:=0X := 0.

Step 3. Prediction: M0=0+0.5=0.5M_0 = 0 + 0.5 = 0.5; Y0=0.5+0+0.5=1Y_0 = 0.5 + 0 + 0.5 = 1.

Answer: M0=0.5M_0 = 0.5 and Y0=1Y_0 = 1.

Exercise 4 · Probability of necessity

In a randomised trial, P(recover∣drug)=0.8P(\text{recover} \mid \text{drug}) = 0.8 and P(recover∣placebo)=0.5P(\text{recover} \mid \text{placebo}) = 0.5. Assuming no one is harmed by the drug, among treated patients who recovered, what share recovered because of the drug?

Show solution

Step 1. PN=0.8−0.50.8=0.375PN = \dfrac{0.8 - 0.5}{0.8} = 0.375.

Answer: 37.5%; the other 62.5% would have recovered anyway.

Exercise 5 · Effect of treatment on the treated

Write the ATT as a counterfactual quantity and say which rung it belongs to.

Show solution

Step 1. ATT=E[Y1−Y0∣X=1]=E[Y∣X=1]−E[Y0∣X=1]ATT = E[Y_1 - Y_0 \mid X = 1] = E[Y \mid X = 1] - E[Y_0 \mid X = 1], using consistency.

Step 2. E[Y0∣X=1]E[Y_0 \mid X = 1] conditions a counterfactual on the actual treatment.

Answer: rung 3 in form, though it is identified by the same assumptions as rung-2 quantities (back-door, Exercise 14).

Part 2 · Proofs

Exercise 6 · Consistency from the SCM

Prove that if X(u)=xX(u) = x then Yx(u)=Y(u)Y_x(u) = Y(u).

Show solution

Step 1. Mx\mathcal M_x differs from M\mathcal M only in XX's equation.

Step 2. For unit uu, the original equation already produces X=xX = x, so replacing it with X:=xX := x changes no value.

Step 3. All other equations and disturbances are identical, so every variable, including YY, takes the same value. ■\blacksquare

Exercise 7 · Linear counterfactuals

Let Y:=βX+UYY := \beta X + U_Y, with UYU_Y arbitrarily dependent on XX. Prove E[Yx′∣X=x,Y=y]=y+β(x′−x)E[Y_{x'} \mid X = x, Y = y] = y + \beta(x' - x).

Show solution

Step 1. Abduction: given X=xX = x, Y=yY = y, we know UY=y−βxU_Y = y - \beta x exactly.

Step 2. Action and prediction: Yx′=βx′+UY=βx′+y−βxY_{x'} = \beta x' + U_Y = \beta x' + y - \beta x.

Step 3. This is non-random given the evidence, so its expectation is itself. ■\blacksquare (Rung 3 collapses to β\beta, a rung-2 quantity, in linear additive models.)

Exercise 8 · Probability of necessity under exogeneity and monotonicity

Assume X⊥ ⁣ ⁣ ⁣⊥(Y0,Y1)X \perp\!\!\!\perp (Y_0, Y_1) and Y1≥Y0Y_1 \ge Y_0. Prove PN=[P(y∣x)−P(y∣x′)]/P(y∣x)PN = [P(y \mid x) - P(y \mid x')]/P(y \mid x).

Show solution

Step 1. PN=P(Y0=0,X=1,Y=1)P(X=1,Y=1)=P(Y0=0,Y1=1,X=1)P(Y1=1,X=1)PN = \dfrac{P(Y_0 = 0, X = 1, Y = 1)}{P(X = 1, Y = 1)} = \dfrac{P(Y_0 = 0, Y_1 = 1, X = 1)}{P(Y_1 = 1, X = 1)} (consistency).

Step 2. By exogeneity, XX factors out: PN=P(Y0=0,Y1=1)/P(Y1=1)PN = P(Y_0 = 0, Y_1 = 1)/P(Y_1 = 1).

Step 3. Monotonicity: Y1=1Y_1 = 1 whenever Y0=1Y_0 = 1, so P(Y0=0,Y1=1)=P(Y1=1)−P(Y0=1)P(Y_0 = 0, Y_1 = 1) = P(Y_1 = 1) - P(Y_0 = 1).

Step 4. By exogeneity P(Yx=1)=P(y∣x)P(Y_x = 1) = P(y \mid x). Substitute. ■\blacksquare

Exercise 9 · Bounds on PNS

From experimental data alone, prove max⁡{0,P(yx)−P(yx′)}≤PNS≤min⁡{P(yx),P(yx′′)}\max\{0, P(y_x) - P(y_{x'})\} \le PNS \le \min\{P(y_x), P(y'_{x'})\}.

Show solution

Step 1. Four response types: (Y1,Y0)∈{(1,1),(1,0),(0,1),(0,0)}(Y_1, Y_0) \in \{(1, 1), (1, 0), (0, 1), (0, 0)\} with probabilities p11,p10,p01,p00p_{11}, p_{10}, p_{01}, p_{00}; PNS=p10PNS = p_{10}.

Step 2. Experiments give P(yx)=p11+p10P(y_x) = p_{11} + p_{10} and P(yx′)=p11+p01P(y_{x'}) = p_{11} + p_{01}.

Step 3. Upper: p10≤p11+p10=P(yx)p_{10} \le p_{11} + p_{10} = P(y_x) and p10≤p10+p00=1−P(yx′)=P(yx′′)p_{10} \le p_{10} + p_{00} = 1 - P(y_{x'}) = P(y'_{x'}).

Step 4. Lower: p10=P(yx)−P(yx′)+p01≥P(yx)−P(yx′)p_{10} = P(y_x) - P(y_{x'}) + p_{01} \ge P(y_x) - P(y_{x'}), and p10≥0p_{10} \ge 0. ■\blacksquare

Exercise 10 · Same experiments, different counterfactuals

Construct two SCMs for binary X,YX, Y with the same P(y∣do⁡(x))P(y \mid \operatorname{do}(x)) for both xx but different PNSPNS.

Show solution

Step 1. Model A: U∼Bernoulli(0.5)U \sim \text{Bernoulli}(0.5), Y:=UY := U. Then P(Y=1∣do⁡(x))=0.5P(Y = 1 \mid \operatorname{do}(x)) = 0.5 for both xx, and nobody responds: PNS=0PNS = 0.

Step 2. Model B: Y:=X⊕UY := X \oplus U (exclusive or). Again P(Y=1∣do⁡(x))=0.5P(Y = 1 \mid \operatorname{do}(x)) = 0.5 for both xx.

Step 3. In Model B, units with U=0U = 0 have Y1=1,Y0=0Y_1 = 1, Y_0 = 0 (helped) and units with U=1U = 1 have Y1=0,Y0=1Y_1 = 0, Y_0 = 1 (harmed): PNS=0.5PNS = 0.5.

Answer: identical at rungs 1 and 2, different at rung 3. ■\blacksquare A zero average effect can hide large offsetting individual effects.

Part 3 · Applied

Exercise 11 · A worker's counterfactual wage

In Day 50's SCM, log⁡W:=1.5+0.08S+0.10A+UW\log W := 1.5 + 0.08S + 0.10A + U_W, a worker has 12 years of schooling and log⁡W=2.6\log W = 2.6. What would her log wage have been with 16 years? Does the answer depend on her (unobserved) ability?

Show solution

Step 1. Abduction: 0.10A+UW=2.6−1.5−0.08(12)=0.140.10A + U_W = 2.6 - 1.5 - 0.08(12) = 0.14. We cannot separate AA from UWU_W, but we do not need to.

Step 2. Action: S:=16S := 16. Ability is upstream of schooling, so it is unchanged.

Step 3. Prediction: log⁡W16=1.5+0.08(16)+0.14=2.92\log W_{16} = 1.5 + 0.08(16) + 0.14 = 2.92.

Answer: 2.92, about 38% higher wages (e0.32−1e^{0.32} - 1). Her ability does not matter because the model is linear and additive (Exercise 7); with heterogeneous returns it would.

Exercise 12 · But-for causation in court

A worker exposed to asbestos develops mesothelioma and sues. A cohort study (exposure as good as random given the covariates) gives a lifetime risk of 2.0% for exposed and 0.5% for comparable unexposed workers. Assuming asbestos never prevents the disease, is it "more likely than not" that the exposure caused this worker's disease?

Show solution

Step 1. Exogeneity and monotonicity give PN=(0.020−0.005)/0.020=0.75PN = (0.020 - 0.005)/0.020 = 0.75.

Step 2. Equivalently, RR=4RR = 4 and PN=1−1/4=0.75PN = 1 - 1/4 = 0.75.

Answer: 75% > 50%: the civil standard is met. The rule "RR > 2 implies PN > 0.5" holds under these assumptions; without monotonicity only bounds are available.

Exercise 13 · How many people does a vaccine protect?

A trial finds infection risks of 2% with vaccine and 10% with placebo. Let yy = "not infected". Bound the share of people who are protected (not infected with the vaccine, infected without), without assuming monotonicity. What does monotonicity add?

Show solution

Step 1. P(y1)=0.98P(y_1) = 0.98 and P(y0)=0.90P(y_0) = 0.90; P(y0′)=0.10P(y'_0) = 0.10.

Step 2. Lower bound: max⁡{0,0.98−0.90}=0.08\max\{0, 0.98 - 0.90\} = 0.08.

Step 3. Upper bound: min⁡{0.98,0.10}=0.10\min\{0.98, 0.10\} = 0.10.

Step 4. With monotonicity (the vaccine never causes infection), PNS=0.98−0.90=0.08PNS = 0.98 - 0.90 = 0.08 exactly.

Answer: between 8% and 10% of people are protected; at most 2% could be harmed (infected only because vaccinated), which is what widens the interval.

Exercise 14 · Effect of training on the trained

Use Day 52's training data: half previously employed (Z=1Z = 1); training rates 30% (Z=1Z = 1) and 70% (Z=0Z = 0); employment P(E=1∣T,Z)P(E = 1 \mid T, Z): Z=1Z = 1: 0.60 untrained, 0.70 trained; Z=0Z = 0: 0.20 untrained, 0.35 trained. Compute E[E0∣T=1]E[E_0 \mid T = 1] and the ATT.

Show solution

Step 1. Composition of the trained: P(Z=1∣T=1)=0.5(0.3)0.5=0.3P(Z = 1 \mid T = 1) = \dfrac{0.5(0.3)}{0.5} = 0.3.

Step 2. With ZZ a back-door set, E[E0∣T=1]=∑zP(E=1∣T=0,z)P(z∣T=1)=0.3(0.60)+0.7(0.20)=0.32E[E_0 \mid T = 1] = \sum_z P(E = 1 \mid T = 0, z)P(z \mid T = 1) = 0.3(0.60) + 0.7(0.20) = 0.32.

Step 3. E[E∣T=1]=0.3(0.70)+0.7(0.35)=0.455E[E \mid T = 1] = 0.3(0.70) + 0.7(0.35) = 0.455.

Step 4. ATT=0.455−0.32=0.135ATT = 0.455 - 0.32 = 0.135.

Answer: training raised the employment of those trained by 13.5 points, slightly more than the ATE of 12.5 points, because the trained are mostly people for whom training helps more.

Exercise 15 · A patient's counterfactual

A patient refused a drug and died. Her family asks whether she would have survived with it. A trial shows survival of 70% with the drug and 60% without. What can be said?

Show solution

Step 1. The question is rung 3: P(survive1∣X=0,died)P(\text{survive}_1 \mid X = 0, \text{died}), the probability of sufficiency.

Step 2. Patients who refuse may differ from trial participants (refusal is not random), so even population-level quantities require care.

Step 3. Treating her as exchangeable with trial patients and assuming monotonicity: PS=P(y∣x)−P(y∣x′)1−P(y∣x′)=0.70−0.600.40=0.25PS = \dfrac{P(y \mid x) - P(y \mid x')}{1 - P(y \mid x')} = \dfrac{0.70 - 0.60}{0.40} = 0.25.

Answer: about a 25% chance she would have survived, under strong assumptions. Without monotonicity, only bounds are available; the honest answer is a range.

Verify in Python

import numpy as np

# Exercise 3: abduction-action-prediction
X, M, Y = 2, 1.5, 4
uM, uY = M - .5 * X, Y - M - X
M0 = .5 * 0 + uM; Y0 = M0 + 0 + uY
print("M_0 =", M0, " Y_0 =", Y0)

# Exercise 11: counterfactual log wage
resid = 2.6 - 1.5 - .08 * 12
print("log W_16 =", round(1.5 + .08 * 16 + resid, 3), " wage gain", f"{np.exp(.32) - 1:.1%}")

# Exercises 4, 12, 13: necessity and sufficiency
PN = lambda p1, p0: (p1 - p0) / p1
print("PN drug:", round(PN(.8, .5), 3), " PN asbestos:", round(PN(.02, .005), 3))
p1, p0 = .98, .90
print("PNS bounds:", (round(max(0, p1 - p0), 3), round(min(p1, 1 - p0), 3)))

# Exercise 10: two models, same experiments, different counterfactuals
rng = np.random.default_rng(59); U = rng.random(1_000_000) < .5
for name, f in [("A: Y = U", lambda x: U), ("B: Y = X xor U", lambda x: np.logical_xor(x, U))]:
    Y1, Y0 = f(1), f(0)
    print(f"{name:15s} P(Y=1|do1) {Y1.mean():.3f}  P(Y=1|do0) {Y0.mean():.3f}  PNS {(Y1 & ~Y0).mean():.3f}")

# Exercise 14: ATT
pT = {1: .3, 0: .7}; pE = {(1, 0): .60, (1, 1): .70, (0, 0): .20, (0, 1): .35}    # key (z, t)
pz_t1 = {z: .5 * pT[z] / .5 for z in (0, 1)}
EY0_T1 = sum(pE[z, 0] * pz_t1[z] for z in (0, 1)); EY_T1 = sum(pE[z, 1] * pz_t1[z] for z in (0, 1))
print(f"E[E_0|T=1] {EY0_T1:.3f}  E[E|T=1] {EY_T1:.3f}  ATT {EY_T1 - EY0_T1:.3f}")

Key takeaways

  • Rung 3 conditions counterfactuals on what actually happened; computing them takes abduction, action and prediction in an SCM.
  • In linear additive models every unit has the same effect; heterogeneity is what makes counterfactuals hard.
  • Probabilities of necessity and sufficiency answer attribution questions; they are identified under exogeneity and monotonicity and otherwise bounded.

Simulation Lab: Counterfactuals & Attribution

Open full screen →

Abduction, action and prediction for one worker's wage, and bounds on how many people a vaccine actually protects.

2381012141618years of schooling Slog wageU = 0.15Y_16
observed log wage
2.610
counterfactual with 16 years
2.930
gain 37.7%
PROBABILITY OF NECESSITY AND SUFFICIENCY (vaccine trial; y = not infected)
00.250.50.751monotone 0.080PNS ∈ [0.080, 0.100]
lower bound
0.080
max(0, P(y₁) − P(y₀))
upper bound
0.100
min(P(y₁), 1 − P(y₀))
PN if monotone
0.082
share of the uninfected vaccinated protected by it
max share harmed
0.020

Left: abduction, action, prediction in Y := 1.5 + β·S + U. The worker's U is read off her observed point (abduction); then schooling is set to a new value (action) and her own line, parallel to the population line, gives the counterfactual (prediction). Right: from an experiment alone, the share of people who respond (PNS) is only bounded; monotonicity pins it down.

Day 58Day 60