Math for Causal Inference

Day 60. Phase 4 Capstone: DAGs Meet Potential Outcomes (SWIGs)

Single-world intervention graphs split each treated node into the value it would have taken and the value we set, so potential outcomes appear in the graph. d-separation in the split graph reads off Phase 3's ignorability assumptions directly, unifying the two languages of causal inference.

Video coming soon
Learning outcomes
  • ●Construct the single-world intervention graph (SWIG) for one or several interventions.
  • ●Read conditional ignorability, and its failure, from d-separation in a SWIG.
  • ●Derive the adjustment formula and the g-formula from SWIG independences plus consistency.
  • ●Carry a policy question through the whole Phase 4 toolkit (DAG, identification, adjustment set, bad controls, selection and mediation).
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

Two languages, one model

Phase 3 wrote assumptions with potential outcomes (Y(a)⊥ ⁣ ⁣ ⁣⊥A∣LY(a) \perp\!\!\!\perp A \mid L). Phase 4 wrote them with graphs (back-door paths). Single-world intervention graphs (Richardson and Robins, 2013) put the potential outcomes into the graph, so ignorability can be checked by d-separation.

Node splitting

To intervene on AA and set it to aa:

  1. Split AA into two halves: the random half AA (the value it would naturally take), which keeps all incoming arrows, and the fixed half aa, which keeps all outgoing arrows.
  2. Relabel every descendant VV of aa as the potential outcome V(a)V(a).

Example: L→A→YL \to A \to Y, L→YL \to Y becomes

L→A,a→Y(a),L→Y(a).L \to A, \qquad a \to Y(a), \qquad L \to Y(a).

There is no edge between AA and Y(a)Y(a): the natural treatment and the potential outcome are linked only through LL.

Reading ignorability

Apply d-separation in the SWIG (fixed nodes are constants and can be treated as conditioned on):

(Y(a)⊥ ⁣ ⁣ ⁣⊥A∣L)SWIG  ⟹  Y(a)⊥ ⁣ ⁣ ⁣⊥A∣L.\big(Y(a) \perp\!\!\!\perp A \mid L\big)_{\text{SWIG}} \;\Longrightarrow\; Y(a) \perp\!\!\!\perp A \mid L.

With consistency (A=a⇒Y(a)=YA = a \Rightarrow Y(a) = Y) and positivity, this gives the adjustment formula

E[Y(a)]=∑lE[Y∣A=a,L=l] P(l).E[Y(a)] = \sum_l E[Y \mid A = a, L = l]\,P(l).

The back-door criterion holds for LL exactly when LL d-separates AA from Y(a)Y(a) in the SWIG.

Several interventions

For sequential treatments A1→L→A2→YA_1 \to L \to A_2 \to Y, split both: the SWIG contains L(a1)L(a_1), A2(a1)A_2(a_1) and Y(a1,a2)Y(a_1, a_2). Sequential ignorability, Y(a1,a2)⊥ ⁣ ⁣ ⁣⊥A1Y(a_1, a_2) \perp\!\!\!\perp A_1 and Y(a1,a2)⊥ ⁣ ⁣ ⁣⊥A2(a1)∣L(a1),A1Y(a_1, a_2) \perp\!\!\!\perp A_2(a_1) \mid L(a_1), A_1, can be read off, and it yields the g-formula of Day 55.

Single world, by design

A SWIG represents one intervention at a time. It cannot express cross-world statements like Y(1,m)⊥ ⁣ ⁣ ⁣⊥M(0)Y(1, m) \perp\!\!\!\perp M(0), which natural mediation effects require (Day 58). That is a feature: assumptions that no experiment could ever check stay visibly separate.

Phase 4 in one table

QuestionTool (Day)
What does my causal story imply?DAG, factorisation, d-separation (46–49)
What happens if we intervene?SCM and the do-operator (50–51)
Which covariates should I adjust for?back-door criterion, good and bad controls (52–53)
Confounder unobserved?front door, do-calculus, ID algorithm (54–56)
Who is in my sample?selection nodes and recoverability (57)
Through which channel?mediation (58)
What would have happened to this unit?counterfactuals (59)
Does my ignorability assumption hold in my graph?SWIGs (60)

Part 1 · Warm-up

Exercise 1 · Draw a SWIG

Draw the SWIG for intervening on AA in L→A→YL \to A \to Y, L→YL \to Y, A→M→YA \to M \to Y.

Show solution

Step 1. Split AA: random half AA keeps L→AL \to A; fixed half aa keeps a→Ya \to Y and a→Ma \to M.

Step 2. Descendants of aa: MM and YY become M(a)M(a) and Y(a)Y(a).

Answer: L→AL \to A; L→Y(a)L \to Y(a); a→M(a)→Y(a)a \to M(a) \to Y(a); a→Y(a)a \to Y(a).

Exercise 2 · Read ignorability

In the SWIG of Exercise 1, is Y(a)⊥ ⁣ ⁣ ⁣⊥AY(a) \perp\!\!\!\perp A? Is Y(a)⊥ ⁣ ⁣ ⁣⊥A∣LY(a) \perp\!\!\!\perp A \mid L?

Show solution

Step 1. Paths from AA to Y(a)Y(a): A←L→Y(a)A \leftarrow L \to Y(a) only (AA has no outgoing edges).

Step 2. Unconditioned, the fork at LL is open: not independent.

Step 3. Given LL, it is blocked: Y(a)⊥ ⁣ ⁣ ⁣⊥A∣LY(a) \perp\!\!\!\perp A \mid L.

Exercise 3 · Unobserved confounding

In U→A→YU \to A \to Y, U→YU \to Y (UU unobserved), draw the SWIG and decide whether any observed variable makes AA ignorable.

Show solution

Step 1. SWIG: U→AU \to A, U→Y(a)U \to Y(a), a→Y(a)a \to Y(a).

Step 2. The path A←U→Y(a)A \leftarrow U \to Y(a) is open unless UU is conditioned on.

Answer: no observed set works; Y(a)⊥̸ ⁣ ⁣ ⁣⊥AY(a) \not\perp\!\!\!\perp A. This is the bow, non-identified (Day 56).

Exercise 4 · Two interventions

Draw the SWIG for intervening on A1A_1 and A2A_2 in A1→L→A2→YA_1 \to L \to A_2 \to Y, A1→YA_1 \to Y, U→LU \to L, U→YU \to Y.

Show solution

Step 1. Split A1A_1 into A1∣a1A_1 \mid a_1; A1A_1 has no parents, a1a_1 points to L(a1)L(a_1) and YY.

Step 2. Split A2A_2: the random half is A2(a1)A_2(a_1) (a descendant of a1a_1), keeping L(a1)→A2(a1)L(a_1) \to A_2(a_1); the fixed half a2a_2 points to YY.

Step 3. YY becomes Y(a1,a2)Y(a_1, a_2), with parents a1,a2,Ua_1, a_2, U.

Answer: a1→L(a1)→A2(a1)a_1 \to L(a_1) \to A_2(a_1), U→L(a1)U \to L(a_1), U→Y(a1,a2)U \to Y(a_1, a_2), a1→Y(a1,a2)a_1 \to Y(a_1, a_2), a2→Y(a1,a2)a_2 \to Y(a_1, a_2), and A1A_1 isolated.

Exercise 5 · What a SWIG cannot show

Why can't a SWIG display the assumption Y(1,m)⊥ ⁣ ⁣ ⁣⊥M(0)Y(1, m) \perp\!\!\!\perp M(0) used for natural direct effects?

Show solution

Step 1. A SWIG contains variables from a single intervention: either M(0)M(0) (intervening on AA with a=0a = 0) or Y(1,m)Y(1, m) (intervening on AA and MM with a=1a = 1), not both.

Step 2. The assumption relates two different interventions on the same unit.

Answer: it is a cross-world assumption; no single-world graph contains both variables, and no experiment can test it.

Part 2 · Proofs

Exercise 6 · From ignorability to the adjustment formula

Assume Y(a)⊥ ⁣ ⁣ ⁣⊥A∣LY(a) \perp\!\!\!\perp A \mid L, consistency and positivity. Prove E[Y(a)]=∑lE[Y∣A=a,L=l]P(l)E[Y(a)] = \sum_l E[Y \mid A = a, L = l]P(l).

Show solution

Step 1. LIE: E[Y(a)]=∑lE[Y(a)∣L=l]P(l)E[Y(a)] = \sum_l E[Y(a) \mid L = l]P(l).

Step 2. Ignorability: E[Y(a)∣L=l]=E[Y(a)∣A=a,L=l]E[Y(a) \mid L = l] = E[Y(a) \mid A = a, L = l] (positivity makes the conditioning event possible).

Step 3. Consistency: on {A=a}\{A = a\}, Y(a)=YY(a) = Y, so this is E[Y∣A=a,L=l]E[Y \mid A = a, L = l].

Step 4. Substitute. ■\blacksquare

Exercise 7 · Back-door implies SWIG separation

Suppose LL satisfies the back-door criterion for (A,Y)(A, Y) in GG. Argue that LL d-separates AA from Y(a)Y(a) in the SWIG.

Show solution

Step 1. In the SWIG, the random half AA has only incoming edges, so every path from AA to Y(a)Y(a) starts with an edge into AA: these are exactly the back-door paths of GG (with descendants of aa relabelled).

Step 2. Directed paths from AA in GG now start at the fixed node aa, not at AA, so they are not AA–Y(a)Y(a) paths.

Step 3. LL contains no descendant of AA, so in the SWIG it contains no potential outcome; conditioning on it opens or blocks the same nodes as in GG.

Step 4. LL blocks every back-door path in GG, hence every AA–Y(a)Y(a) path in the SWIG. ■\blacksquare

Exercise 8 · The g-formula from sequential ignorability

For the SWIG of Exercise 4 (with no UU–A2A_2 edge), assume Y(a1,a2)⊥ ⁣ ⁣ ⁣⊥A1Y(a_1, a_2) \perp\!\!\!\perp A_1, Y(a1,a2)⊥ ⁣ ⁣ ⁣⊥A2(a1)∣A1,L(a1)Y(a_1, a_2) \perp\!\!\!\perp A_2(a_1) \mid A_1, L(a_1), L(a1)⊥ ⁣ ⁣ ⁣⊥A1L(a_1) \perp\!\!\!\perp A_1, and consistency. Prove E[Y(a1,a2)]=∑lE[Y∣a1,l,a2]P(l∣a1)E[Y(a_1, a_2)] = \sum_l E[Y \mid a_1, l, a_2]P(l \mid a_1).

Show solution

Step 1. By the first assumption and consistency of LL: E[Y(a1,a2)]=E[Y(a1,a2)∣A1=a1]=∑lE[Y(a1,a2)∣A1=a1,L=l]P(l∣a1)E[Y(a_1, a_2)] = E[Y(a_1, a_2) \mid A_1 = a_1] = \sum_l E[Y(a_1, a_2) \mid A_1 = a_1, L = l]P(l \mid a_1).

Step 2. Second assumption: condition additionally on A2=a2A_2 = a_2 (which equals A2(a1)A_2(a_1) when A1=a1A_1 = a_1): E[Y(a1,a2)∣a1,l]=E[Y(a1,a2)∣a1,l,A2=a2]E[Y(a_1, a_2) \mid a_1, l] = E[Y(a_1, a_2) \mid a_1, l, A_2 = a_2].

Step 3. Consistency: when A1=a1A_1 = a_1 and A2=a2A_2 = a_2, Y(a1,a2)=YY(a_1, a_2) = Y.

Step 4. Substitute. ■\blacksquare

Exercise 9 · M-bias in a SWIG

In U1→AU_1 \to A, U1→MU_1 \to M, U2→MU_2 \to M, U2→YU_2 \to Y, A→YA \to Y, show with the SWIG that Y(a)⊥ ⁣ ⁣ ⁣⊥AY(a) \perp\!\!\!\perp A but not Y(a)⊥ ⁣ ⁣ ⁣⊥A∣MY(a) \perp\!\!\!\perp A \mid M.

Show solution

Step 1. SWIG: U1→AU_1 \to A, U1→MU_1 \to M, U2→MU_2 \to M, U2→Y(a)U_2 \to Y(a), a→Y(a)a \to Y(a). MM is not a descendant of aa, so it is not relabelled.

Step 2. The only AA–Y(a)Y(a) path: A←U1→M←U2→Y(a)A \leftarrow U_1 \to M \leftarrow U_2 \to Y(a), with a collider at MM.

Step 3. Unconditioned: blocked, so Y(a)⊥ ⁣ ⁣ ⁣⊥AY(a) \perp\!\!\!\perp A. Given MM: open.

Answer: treatment is marginally ignorable but not given MM: the potential-outcome version of M-bias. ■\blacksquare

Exercise 10 · Why the front door is not "ignorability"

In the front-door graph U→AU \to A, U→YU \to Y, A→M→YA \to M \to Y, show that no observed set makes Y(a)⊥ ⁣ ⁣ ⁣⊥AY(a) \perp\!\!\!\perp A, and explain how identification still succeeds.

Show solution

Step 1. SWIG: U→AU \to A, U→Y(a)U \to Y(a), a→M(a)→Y(a)a \to M(a) \to Y(a).

Step 2. The path A←U→Y(a)A \leftarrow U \to Y(a) is open, and the only observed candidate, M(a)M(a), is not on it.

Step 3. So no conditioning set gives ignorability of AA.

Step 4. Identification works through two separate ignorabilities: M(a)⊥ ⁣ ⁣ ⁣⊥AM(a) \perp\!\!\!\perp A (in this SWIG) and Y(m)⊥ ⁣ ⁣ ⁣⊥M∣AY(m) \perp\!\!\!\perp M \mid A (in the SWIG for intervening on MM), chained as in Day 54. ■\blacksquare

Part 3 · Applied

Exercise 11 · Microfinance and women's decision-making

An NGO asks whether microloans to women (AA) increase their say in household decisions (YY). Available variables: baseline education EE, baseline household assets HH, village VV (loan officers choose villages based on market access, which also affects bargaining norms), business started after the loan BB, and survey participation SS (husbands sometimes refuse interviews when the wife's power rises). Lay out a Phase 4 analysis plan.

Show solution

Step 1. DAG: E,H,V→AE, H, V \to A; E,H,V→YE, H, V \to Y; A→B→YA \to B \to Y; A→YA \to Y; Y→SY \to S.

Step 2. Identification: {E,H,V}\{E, H, V\} blocks the back-door paths and contains no descendants: admissible (SWIG: Y(a)⊥ ⁣ ⁣ ⁣⊥A∣E,H,VY(a) \perp\!\!\!\perp A \mid E, H, V).

Step 3. Bad controls: business BB is a mediator; exclude for the total effect.

Step 4. Selection: SS depends on YY, so analysing respondents biases results; collect refusal data and use bounds or weights based on predictors of refusal (Day 57).

Step 5. Mechanism: the share via business start is a mediation question needing BB–YY unconfoundedness (Day 58).

Answer: adjust for E,H,VE, H, V; don't adjust for BB; address non-response explicitly; treat mediation as secondary with sensitivity checks.

Exercise 12 · Auditing a regression

A paper estimates the return to a vocational degree DD by regressing earnings YY on DD, age, parental income, current occupation and current job tenure. Using a DAG, list which controls are appropriate and which are not.

Show solution

Step 1. Age and parental income precede the degree and affect earnings: confounders; keep.

Step 2. Occupation and tenure are affected by the degree: mediators (and colliders if ability affects them): exclude for the total return.

Step 3. Missing: ability or school grades, which affect both DD and YY; if unobserved, the estimate remains biased, and a sensitivity analysis is needed.

Answer: keep age and parental income; drop occupation and tenure; flag ability.

Exercise 13 · Sequential HIV treatment, by simulation

In the simulated clinic below, treatment at visit 1 (A1A_1, randomised) raises CD4 counts LL; doctors give treatment at visit 2 (A2A_2) mainly to patients with low CD4; unobserved health UU affects CD4 and viral suppression YY. The true effect of "always treat" versus "never treat" is 0.45. Compare the naive comparison, a regression on A1,L,A2A_1, L, A_2, and the g-formula.

Show solution

Step 1. Naive comparison (always-treated versus never-treated patients): biased, because A2A_2 depends on LL, which depends on UU. The code gives about 0.38.

Step 2. Regression on A1,L,A2A_1, L, A_2: LL is a mediator for A1A_1 and a collider (A1→L←UA_1 \to L \leftarrow U); the sum of coefficients is about 0.41.

Step 3. g-formula: ∑lE[Y∣a1,l,a2]P(l∣a1)\sum_l E[Y \mid a_1, l, a_2]P(l \mid a_1) at (1,1)(1, 1) minus (0,0)(0, 0): about 0.45.

Answer: only the g-formula, justified by sequential ignorability in the SWIG, recovers the effect; Day 96 develops it and its weighting cousin.

Exercise 14 · One question, several designs

A health system asks for the effect of ICU admission AA on 30-day mortality YY. For each data situation, name the Phase 4 strategy or say "not identified": (a) severity scores used for admission are recorded; (b) severity is not recorded, but admission affects mortality only through hours of ventilation, which are not confounded with mortality given admission; (c) severity is not recorded and nothing else is known; (d) only patients who survived 24 hours are in the data.

Show solution

Step 1. (a) Back-door adjustment for severity (and other admission criteria) (Day 52).

Step 2. (b) Front door through ventilation hours (Day 54), if its strong assumptions are credible.

Step 3. (c) The bow: not identified (Day 56); bounds, sensitivity, or an instrument such as bed availability (Phase 5).

Step 4. (d) Selection on a variable affected by both admission and severity: a collider (Day 57); estimates for survivors are biased unless selection can be modelled.

Exercise 15 · Reading a SWIG for a vaccine study

Observational vaccine data: age G→G \to vaccination AA, G→G \to infection YY; health-seeking behaviour HH (unobserved) →A\to A and H→H \to testing TT; Y→TY \to T; only tested people are analysed. Draw the SWIG for AA and decide whether Y(a)⊥ ⁣ ⁣ ⁣⊥A∣GY(a) \perp\!\!\!\perp A \mid G, and what the testing restriction does.

Show solution

Step 1. SWIG: G→AG \to A, H→AH \to A, G→Y(a)G \to Y(a), a→Y(a)a \to Y(a), H→T(a)H \to T(a), Y(a)→T(a)Y(a) \to T(a) (testing is a descendant of aa through YY).

Step 2. Paths from AA to Y(a)Y(a): A←G→Y(a)A \leftarrow G \to Y(a) (blocked by GG) and A←H→T(a)←Y(a)A \leftarrow H \to T(a) \leftarrow Y(a) (collider at T(a)T(a), blocked if not conditioned).

Step 3. So Y(a)⊥ ⁣ ⁣ ⁣⊥A∣GY(a) \perp\!\!\!\perp A \mid G in the full population.

Step 4. Restricting to tested people conditions on TT, opening A←H→T←YA \leftarrow H \to T \leftarrow Y.

Answer: age adjustment suffices in population data, but tested-only data are biased by health-seeking behaviour (the motivation for test-negative designs, which make further assumptions).

Verify in Python

import numpy as np
import networkx as nx

dsep = getattr(nx, "is_d_separator", None) or nx.d_separated   # name changed in networkx 3.3

def swig(G, A):
    """Split node A into random half A and fixed half 'a'; relabel descendants of A as V(a)."""
    desc = nx.descendants(G, A)
    name = lambda v: f"{v}(a)" if v in desc else v
    S = nx.DiGraph(); S.add_nodes_from([name(v) for v in G] + ["a"])
    for u, v in G.edges:
        S.add_edge("a" if u == A else name(u), name(v))
    return S

G = nx.DiGraph([("L", "A"), ("L", "Y"), ("A", "Y"), ("A", "M"), ("M", "Y")])
S = swig(G, "A")
print("SWIG edges:", sorted(S.edges))
print("Y(a) _||_ A:", dsep(S, {"Y(a)"}, {"A"}, {"a"}), "| given L:", dsep(S, {"Y(a)"}, {"A"}, {"a", "L"}))

Mb = swig(nx.DiGraph([("U1", "A"), ("U1", "M"), ("U2", "M"), ("U2", "Y"), ("A", "Y")]), "A")
print("M-bias: Y(a) _||_ A:", dsep(Mb, {"Y(a)"}, {"A"}, {"a"}), "| given M:", dsep(Mb, {"Y(a)"}, {"A"}, {"a", "M"}))

V = swig(nx.DiGraph([("G", "A"), ("H", "A"), ("G", "Y"), ("A", "Y"), ("H", "T"), ("Y", "T")]), "A")
print("vaccine: Y(a) _||_ A | G:", dsep(V, {"Y(a)"}, {"A"}, {"a", "G"}), "| G, T(a):", dsep(V, {"Y(a)"}, {"A"}, {"a", "G", "T(a)"}))

# Exercise 13: sequential treatment and the g-formula
rng = np.random.default_rng(60); n = 2_000_000
def clinic(a1=None, a2=None):
    U = rng.random(n) < .5
    A1 = rng.random(n) < .5 if a1 is None else np.full(n, a1, bool)
    L = rng.random(n) < .2 + .4 * A1 + .3 * U                       # high CD4
    A2 = rng.random(n) < (.8 - .6 * L) if a2 is None else np.full(n, a2, bool)
    Y = rng.random(n) < .1 + .2 * A1 + .25 * A2 + .3 * U             # viral suppression
    return A1, L, A2, Y
A1, L, A2, Y = clinic()
truth = clinic(1, 1)[3].mean() - clinic(0, 0)[3].mean()
g = lambda a1, a2: sum(Y[(A1 == a1) & (L == l) & (A2 == a2)].mean() * (L[A1 == a1] == l).mean() for l in (0, 1))
b = np.linalg.lstsq(np.column_stack([np.ones(n), A1, L, A2]).astype(float), Y.astype(float), rcond=None)[0]
print(f"truth {truth:.3f}  naive {Y[A1 & A2].mean() - Y[~A1 & ~A2].mean():.3f}  regression {b[1] + b[3]:.3f}  g-formula {g(1, 1) - g(0, 0):.3f}")

Key takeaways

  • A SWIG splits each intervened node into its natural and fixed halves and relabels descendants as potential outcomes.
  • Ignorability is d-separation in the SWIG; with consistency and positivity it yields the adjustment formula and, for sequential treatments, the g-formula.
  • SWIGs keep single-world assumptions testable in principle and cross-world assumptions visibly separate. Phase 5 now turns to designs (instruments, differences-in-differences, discontinuities) for when no admissible set is observed.

Simulation Lab: Single-World Intervention Graphs

Open full screen →

Split the treatment node, relabel potential outcomes, and read ignorability straight off the graph.

ORIGINAL DAG
LAMY
SWIG FOR do(A = a)
LAaM(a)Y(a)
Y(a) ⫫ A | L: holds (d-separation in the SWIG).
A ← L → Y(a) — blocked at L

The SWIG splits the treatment into its natural value A (keeps incoming arrows) and the value we set, a (keeps outgoing arrows); everything downstream becomes a potential outcome. Click nodes to condition on them. Ignorability Y(a) ⫫ A | L holds exactly when every path between A and Y(a) is blocked. Dashed nodes are unobserved.

Day 59Day 61