Math for Causal Inference

Day 49. d-Separation

One rule for reading every conditional independence a DAG implies. A path is blocked by a conditioning set if it has a chain or fork whose middle is conditioned on, or a collider that is not; two sets are d-separated if every path between them is blocked.

Video coming soon
Learning outcomes
  • ●Decide whether a path is open or blocked given a conditioning set.
  • ●Decide whether two variables are d-separated by enumerating paths.
  • ●Prove the Markov blanket property and that the local Markov property is a special case of d-separation.
  • ●Use d-separation to compare candidate DAGs, check instruments and reason about missing data.
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

Blocking a path

Let Z\mathbf Z be a set of conditioned variables. A path between XX and YY is blocked by Z\mathbf Z if it contains at least one node MM such that

  1. MM is the middle of a chain (→M→\to M \to) or fork (←M→\leftarrow M \to) and M∈ZM \in \mathbf Z, or
  2. MM is a collider (→M←\to M \leftarrow) and neither MM nor any descendant of MM is in Z\mathbf Z.

A path that is not blocked is open (or active). Open paths carry association.

d-separation

XX and YY are d-separated by Z\mathbf Z, written (X⊥ ⁣ ⁣ ⁣⊥Y∣Z)G(X \perp\!\!\!\perp Y \mid \mathbf Z)_G, if every path between them is blocked by Z\mathbf Z. Otherwise they are d-connected.

The global Markov property

If PP factorises according to GG (Day 47), then

(X⊥ ⁣ ⁣ ⁣⊥Y∣Z)G  ⟹  X⊥ ⁣ ⁣ ⁣⊥Y∣Z in P.(X \perp\!\!\!\perp Y \mid \mathbf Z)_G \;\Longrightarrow\; X \perp\!\!\!\perp Y \mid \mathbf Z \text{ in } P.

d-separation is sound (it never claims a false independence) and, under faithfulness, complete (every independence in PP is a d-separation). The local Markov property is the special case "parents separate a node from its other non-descendants".

Recipe

  1. List every path between XX and YY (ignoring arrow directions, no repeated nodes).
  2. For each path, classify each interior node as chain, fork or collider.
  3. The path is open only if every chain/fork middle is outside Z\mathbf Z and every collider is in Z\mathbf Z or has a descendant in Z\mathbf Z.
  4. XX and YY are d-separated if no path is open.

Software does this efficiently (the "Bayes-ball" algorithm, or networkx.is_d_separator). The lab lets you click a conditioning set and watch paths open and close.

Non-monotonicity

Adding a variable to Z\mathbf Z can open a path (if it is a collider or a collider's descendant) as well as close one. "Control for more" is not automatically safer.

Markov blanket

The Markov blanket of VV is its parents, children and the other parents of its children. Given its blanket, VV is d-separated from every other variable: the blanket is the smallest set worth knowing to predict VV.

Part 1 · Warm-up

Exercises 1–5 use this DAG: Z→XZ \to X, Z→WZ \to W, W→YW \to Y, X→MX \to M, M→YM \to Y, X→CX \to C, Y→CY \to C.

Exercise 1 · List the paths

List every path between XX and YY and classify the interior nodes.

Show solution

Step 1. X→M→YX \to M \to Y: MM is a chain middle.

Step 2. X←Z→W→YX \leftarrow Z \to W \to Y: ZZ is a fork, WW a chain middle.

Step 3. X→C←YX \to C \leftarrow Y: CC is a collider.

Answer: three paths.

Exercise 2 · Nothing conditioned

Are XX and YY d-separated by the empty set?

Show solution

Step 1. Path 1: chain through MM, not conditioned: open.

Step 2. One open path suffices.

Answer: no, they are d-connected. (Path 2 is also open; path 3 is blocked by the unconditioned collider.)

Exercise 3 · Conditioning on MM and WW

Are XX and YY d-separated by {M,W}\{M, W\}?

Show solution

Step 1. Path 1: MM conditioned, chain: blocked.

Step 2. Path 2: WW conditioned, chain: blocked.

Step 3. Path 3: collider CC not conditioned and has no descendants: blocked.

Answer: yes, d-separated.

Exercise 4 · Adding CC

Are XX and YY d-separated by {M,W,C}\{M, W, C\}?

Show solution

Step 1. Paths 1 and 2 stay blocked.

Step 2. Path 3: the collider CC is now conditioned: open.

Answer: no. Adding CC re-connects XX and YY (non-monotonicity).

Exercise 5 · A different pair

Is ZZ d-separated from MM by {X}\{X\}?

Show solution

Step 1. Z→X→MZ \to X \to M: chain at XX, conditioned: blocked.

Step 2. Z→W→Y←MZ \to W \to Y \leftarrow M: collider YY; neither YY nor its descendant CC is conditioned: blocked.

Step 3. Z→W→Y→C←X→MZ \to W \to Y \to C \leftarrow X \to M: collider CC not conditioned: blocked (also XX is a fork middle, conditioned).

Step 4. Z→X→C←Y←MZ \to X \to C \leftarrow Y \leftarrow M: XX is a chain middle, conditioned: blocked.

Answer: yes, every path is blocked.

Part 2 · Proofs

Exercise 6 · Neighbours are never separated

Prove that if X→YX \to Y is an edge, no set Z\mathbf Z (excluding X,YX, Y) d-separates them.

Show solution

Step 1. The one-edge path X→YX \to Y has no interior nodes.

Step 2. Blocking requires an interior node satisfying condition 1 or 2; there is none.

Step 3. So this path is open for every Z\mathbf Z, and X,YX, Y are d-connected. ■\blacksquare

This is why missing arrows, not present ones, carry the testable content of a DAG.

Exercise 7 · Local Markov from d-separation

Prove that every node VV is d-separated from any non-descendant NN (not a parent) by pa⁡(V)\operatorname{pa}(V).

Show solution

Step 1. Take any path from VV to NN. Case A: it starts with an edge into VV, V←PV \leftarrow P, so PP is a parent.

Step 2. At PP the path continues either ←P←\leftarrow P \leftarrow (chain) or ←P→\leftarrow P \to (fork). PP cannot be a collider, because the edge P→VP \to V points out of it. P∈pa⁡(V)P \in \operatorname{pa}(V) is conditioned, so the path is blocked.

Step 3. Case B: the path starts V→C1V \to C_1. Follow it while the arrows keep pointing forward: V→C1→C2→…V \to C_1 \to C_2 \to \dots. All these nodes are descendants of VV.

Step 4. NN is not a descendant, so the arrows must reverse somewhere: there is a collider CkC_k with →Ck←\to C_k \leftarrow, and CkC_k is a descendant of VV.

Step 5. Neither CkC_k nor its descendants can be parents of VV (that would create a cycle). So the collider is unconditioned with no conditioned descendant: blocked. ■\blacksquare

Exercise 8 · The Markov blanket

Prove that VV is d-separated from every node outside its Markov blanket B\mathbf B (parents, children, children's other parents) given B\mathbf B.

Show solution

Step 1. Paths leaving through a parent PP: as in Exercise 7, PP is a conditioned chain or fork middle: blocked.

Step 2. Paths leaving through a child CC and continuing V→C→V \to C \to: CC is a conditioned chain middle: blocked.

Step 3. Paths continuing V→C←QV \to C \leftarrow Q: CC is a conditioned collider, so open at CC; but then QQ is a co-parent, in B\mathbf B.

Step 4. At QQ the path continues ←Q←\leftarrow Q \leftarrow or ←Q→\leftarrow Q \to (not a collider, since Q→CQ \to C points out). QQ is conditioned: blocked.

Step 5. Every path is blocked. ■\blacksquare

Exercise 9 · No common ancestor, no association

Prove that if XX and YY have no common ancestor (counting each node as its own ancestor), they are d-separated by the empty set.

Show solution

Step 1. With Z=∅\mathbf Z = \varnothing, a path is open only if it has no colliders.

Step 2. A collider-free path has at most one node where the arrows point away on both sides, otherwise there would be a collider between two such nodes. Call that node SS (possibly an endpoint).

Step 3. From SS, both halves of the path are directed paths towards XX and towards YY, so SS is a common ancestor.

Step 4. There is none, so no path is open, and X,YX, Y are d-separated. ■\blacksquare (Reichenbach's principle: dependence requires a causal link or a common cause, absent selection.)

Exercise 10 · More control can hurt

Give a three-node DAG in which X⊥ ⁣ ⁣ ⁣⊥YX \perp\!\!\!\perp Y is implied but X⊥ ⁣ ⁣ ⁣⊥Y∣WX \perp\!\!\!\perp Y \mid W is not, and one in which the reverse holds.

Show solution

Step 1. Collider X→W←YX \to W \leftarrow Y: the only path is blocked given ∅\varnothing and open given WW.

Step 2. Chain X→W→YX \to W \to Y (or fork X←W→YX \leftarrow W \to Y): the only path is open given ∅\varnothing and blocked given WW.

Answer: d-separation is not monotone in the conditioning set; which variables to condition on depends on the graph, not on "more is better". ■\blacksquare

Part 3 · Applied

Exercise 11 · Two stories about microcredit

DAG 1: education E→E \to loan L→L \to income II. DAG 2: E→LE \to L, E→IE \to I, L→IL \to I. Which testable independence separates them? In survey data, the regression of income on loans and education gives a large, precise education coefficient. Which DAG survives?

Show solution

Step 1. DAG 1 implies E⊥ ⁣ ⁣ ⁣⊥I∣LE \perp\!\!\!\perp I \mid L (chain blocked at LL).

Step 2. DAG 2 has the edge E→IE \to I, so by Exercise 6 no independence between EE and II is implied.

Step 3. In a linear model, E⊥ ⁣ ⁣ ⁣⊥I∣LE \perp\!\!\!\perp I \mid L means a zero education coefficient once loans are included.

Answer: a large, precise coefficient rejects DAG 1; DAG 2 survives (education affects income other than through loans).

Exercise 12 · Pollution, allergies and the emergency room

Air pollution P→P \to asthma attack A←A \leftarrow allergy GG, and A→A \to emergency visit EE. Pollution and allergy have no common cause. Is P⊥ ⁣ ⁣ ⁣⊥GP \perp\!\!\!\perp G implied? Is P⊥ ⁣ ⁣ ⁣⊥G∣EP \perp\!\!\!\perp G \mid E? What does this mean for a study using only emergency-room records?

Show solution

Step 1. One path: P→A←GP \to A \leftarrow G, a collider at AA.

Step 2. Given nothing: blocked, so P⊥ ⁣ ⁣ ⁣⊥GP \perp\!\!\!\perp G.

Step 3. Given EE: EE is a descendant of the collider, so the path opens: not d-separated.

Answer: among ER patients, pollution and allergies will look negatively related (an attack on a clean-air day is more likely to be allergic). ER-only data condition on a collider's descendant.

Exercise 13 · School meals

A DAG for a school-meals programme: household income I→I \to meals MM, I→I \to attendance AA, M→M \to nutrition N→N \to test score TT, A→TA \to T, rainfall R→AR \to A. Decide: (a) M⊥ ⁣ ⁣ ⁣⊥RM \perp\!\!\!\perp R? (b) M⊥ ⁣ ⁣ ⁣⊥R∣TM \perp\!\!\!\perp R \mid T? (c) M⊥ ⁣ ⁣ ⁣⊥T∣{N,I}M \perp\!\!\!\perp T \mid \{N, I\}?

Show solution

Step 1. (a) Paths MM–RR: M←I→A←RM \leftarrow I \to A \leftarrow R (collider AA) and M→N→T←A←RM \to N \to T \leftarrow A \leftarrow R (collider TT). Both blocked: yes.

Step 2. (b) Conditioning on TT opens the collider in the second path: M→N→T←A←RM \to N \to T \leftarrow A \leftarrow R is open. Also TT is a descendant of AA, opening the first path. Not d-separated.

Step 3. (c) Paths MM–TT: M→N→TM \to N \to T (blocked by NN) and M←I→A→TM \leftarrow I \to A \to T (blocked by II, a fork). Yes.

Answer: yes, no, yes. Statement (c) is testable: given nutrition and income, meals should not predict test scores.

Exercise 14 · Checking an instrument

The Vietnam draft lottery ZZ affects military service DD, which affects later earnings YY; unobserved motivation UU affects both DD and YY. (a) Is Z⊥ ⁣ ⁣ ⁣⊥UZ \perp\!\!\!\perp U implied? (b) Is Z⊥ ⁣ ⁣ ⁣⊥Y∣DZ \perp\!\!\!\perp Y \mid D implied? (c) Why is "regress earnings on the lottery, controlling for service" a mistake?

Show solution

Step 1. (a) Path Z→D←UZ \to D \leftarrow U has a collider at DD: blocked. Yes, Z⊥ ⁣ ⁣ ⁣⊥UZ \perp\!\!\!\perp U (the lottery is random).

Step 2. (b) Paths ZZ–YY: Z→D→YZ \to D \to Y (blocked by DD) and Z→D←U→YZ \to D \leftarrow U \to Y (collider DD conditioned: open). Not d-separated.

Step 3. (c) Conditioning on service opens Z→D←U→YZ \to D \leftarrow U \to Y, so the "direct effect" of the lottery picks up motivation differences: among veterans, those with losing lottery numbers volunteered.

Answer: use the lottery as an instrument (Phase 5), not as a control alongside service.

Exercise 15 · When is survey non-response ignorable?

In a household survey, income YY is missing when the response indicator R=0R = 0. Covariates XX (region, household size) are always observed. Draw two DAGs, one where RR depends only on XX and one where it also depends on YY, and state the d-separation that makes complete-case analysis within XX valid.

Show solution

Step 1. DAG A: X→YX \to Y, X→RX \to R. Paths YY–RR: Y←X→RY \leftarrow X \to R, blocked by XX. So Y⊥ ⁣ ⁣ ⁣⊥R∣XY \perp\!\!\!\perp R \mid X: missing at random (Day 14).

Step 2. DAG B: add Y→RY \to R (rich households refuse). Now YY and RR are adjacent; no set separates them.

Step 3. Under DAG A, P(y∣x,R=1)=P(y∣x)P(y \mid x, R = 1) = P(y \mid x), so complete cases within each XX cell (or weighting by 1/P(R=1∣X)1/P(R = 1 \mid X)) recover the income distribution.

Answer: the condition is Y⊥ ⁣ ⁣ ⁣⊥R∣XY \perp\!\!\!\perp R \mid X; under DAG B it fails (missing not at random) and only bounds or extra assumptions help.

Verify in Python

import networkx as nx

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

G = nx.DiGraph([("Z", "X"), ("Z", "W"), ("W", "Y"), ("X", "M"), ("M", "Y"), ("X", "C"), ("Y", "C")])
print("paths X-Y:", list(nx.all_simple_paths(G.to_undirected(), "X", "Y")))
for Zs in [set(), {"M", "W"}, {"M", "W", "C"}]:
    print(f"X _||_ Y | {sorted(Zs)}:", dsep(G, {"X"}, {"Y"}, Zs))
print("Z _||_ M | X:", dsep(G, {"Z"}, {"M"}, {"X"}))

# Exercise 13: school meals
S = nx.DiGraph([("I", "M"), ("I", "A"), ("M", "N"), ("N", "T"), ("A", "T"), ("R", "A")])
print("M _||_ R:", dsep(S, {"M"}, {"R"}, set()), "| M _||_ R | T:", dsep(S, {"M"}, {"R"}, {"T"}),
      "| M _||_ T | N,I:", dsep(S, {"M"}, {"T"}, {"N", "I"}))

# Exercise 14: draft lottery
L = nx.DiGraph([("Z", "D"), ("D", "Y"), ("U", "D"), ("U", "Y")])
print("Z _||_ U:", dsep(L, {"Z"}, {"U"}, set()), "| Z _||_ Y | D:", dsep(L, {"Z"}, {"Y"}, {"D"}))

# All pairwise marginal independences implied by the school-meals DAG
nodes = sorted(S)
print("marginally independent pairs:", [(a, b) for i, a in enumerate(nodes) for b in nodes[i + 1:] if dsep(S, {a}, {b}, set())])

Key takeaways

  • A path is blocked by a conditioned chain or fork middle, or by an unconditioned collider with no conditioned descendants.
  • d-separation (all paths blocked) implies conditional independence in every distribution that factorises over the DAG.
  • Conditioning can open paths as well as close them; the graph, not intuition, decides what to control for.

Simulation Lab: d-Separation Explorer

Open full screen →

Pick two variables and a conditioning set in a school-meals DAG; every path is listed as open or blocked, with the reason.

Clicking a node sets
IncomeMealsAttendanceNutritionTest scoreRainfallClinic visit
Meals and Rainfall are d-connected given {Test score}.
Meals ← Income → Attendance ← Rainfall
Income: fork · Attendance: collider — open
Meals → Nutrition → Test score ← Attendance ← Rainfall
Nutrition: chain · Test score: collider · Attendance: chain — open
Meals → Nutrition → Clinic visit ← Test score ← Attendance ← Rainfall
Nutrition: chain · Clinic visit: collider · Test score: chain · Attendance: chain — blocked at Clinic visit
Try: Meals and Rainfall given nothing, then given Test score (a collider's descendant), then add Attendance.

Pick the two variables and click nodes to add or remove them from the conditioning set. Every path between the two is listed with its junctions; a path is blocked by a conditioned chain or fork, or by a collider with nothing conditioned at or below it. Open paths are drawn in orange.

Day 48Day 50