Day 55. The Rules of do-Calculus
Three rules, each licensed by a d-separation in a modified graph, let you add or remove observations, swap actions for observations, and add or remove actions. Every identifiable causal effect can be derived with them.
- ●Build the modified graphs G with incoming or outgoing arrows removed.
- ●State the three rules of do-calculus and check their graphical conditions.
- ●Derive the back-door and front-door formulas, and the g-formula for two sequential treatments, step by step.
- ●Recognise when no sequence of rules can work and show non-identification with two models.
Theory
Modified graphs
For sets of nodes in :
- : delete all arrows into (the graph after intervening on );
- : delete all arrows out of (only back-door paths from remain);
- : both.
The three rules
For disjoint sets :
Rule 1 (insert or delete observations).
Rule 2 (exchange action and observation).
Rule 3 (insert or delete actions).
where is the set of -nodes that are not ancestors of any -node in .
Reading the rules
- Rule 1 is d-separation applied in the post-intervention world.
- Rule 2 says: if has no open back-door paths to (given ), seeing is as good as setting it. It generalises the back-door criterion.
- Rule 3 says: if cannot reach through any causal path (given the rest), setting it changes nothing. The subtlety handles conditioning on descendants of .
Identification as derivation
A causal query is identified if the rules, plus ordinary probability, transform it into an expression with no . The rules are complete: if no derivation exists, the effect is not identified from observational data in that graph (Shpitser & Pearl, 2006). Day 56 gives an algorithm that finds the derivation automatically.
Standard moves
- Condition and sum: .
- Remove the from with Rule 3 (if is not a descendant) or Rule 2.
- Turn into inside with Rule 2.
Part 1 · Warm-up
Exercises 1 and 4 use : , , .
Exercise 1 · Modified graphs
Write the edges of , and .
Show solution
Step 1. : remove . Left: , , .
Step 2. : remove , . Left: , .
Step 3. : has no incoming arrows, so .
Exercise 2 · Randomised treatment
In with randomised (no parents), use Rule 2 to show .
Show solution
Step 1. Rule 2 with empty outer and , and : condition .
Step 2. removes : no edges remain, so and are d-separated.
Answer: Rule 2 applies: .
Exercise 3 · Actions that cannot matter
If is not an ancestor of , show with Rule 3.
Show solution
Step 1. Rule 3 with empty : condition .
Step 2. In , has no incoming arrows; any path from starts .
Step 3. Since is not an ancestor of , such a path must contain a collider (it cannot be directed all the way to ); unconditioned, it is blocked.
Answer: d-separated, so .
Exercise 4 · Rule 1 in action
In , is ?
Show solution
Step 1. Rule 1 condition: .
Step 2. In , paths –: (fork at , conditioned: blocked).
Step 3. is not a path to ; and is gone, so no other path exists.
Answer: yes; once is set, (a side effect of ) carries no information about .
Exercise 5 · Name the rule
Which rule justifies each step? (a) for a pre-treatment . (b) when blocks the back-door paths. (c) Dropping a measured side effect of treatment from the conditioning set.
Show solution
Step 1. (a) Rule 3 (deleting an action that cannot affect ).
Step 2. (b) Rule 2 (exchanging the action for the observation ).
Step 3. (c) Rule 1 (deleting an observation).
Part 2 · Proofs
Exercise 6 · The back-door formula by do-calculus
Let satisfy the back-door criterion for . Derive .
Show solution
Step 1. Condition and sum: .
Step 2. Rule 3 for : need . In , paths from leave through its children; since no node is a descendant of , each such path meets a collider and is blocked. So .
Step 3. Rule 2 for : need . In only back-door paths from remain, and blocks them all. So .
Step 4. Substitute. (This also proves fact (b) assumed on Day 52.)
Exercise 7 · Front door, first piece
In the front-door graph , , ( unobserved), show .
Show solution
Step 1. Rule 2 condition: .
Step 2. removes . Remaining paths –: , with a collider at : blocked.
Answer: Rule 2 applies.
Exercise 8 · Front door, second piece
In the same graph, show .
Show solution
Step 1. Condition and sum: .
Step 2. Rule 2 on the first factor: . Removing leaves the path , blocked by (chain). So .
Step 3. Rule 3 on the second factor: . Removing leaves with a collider at : blocked. So .
Step 4. Substitute.
Exercise 9 · Front door, assembled
Complete the derivation of .
Show solution
Step 1. Condition and sum: .
Step 2. The second factor is (Exercise 7).
Step 3. Rule 2 on the first: . Removing arrows into and out of leaves no path – except through , which is conditioned. So .
Step 4. Rule 3: . With arrows into and removed, is isolated. So .
Step 5. By Exercise 8, . Substitute.
Exercise 10 · Two models, one distribution
In the "bow" graph with , show that is not identified by exhibiting two SCMs with the same and different interventional distributions.
Show solution
Step 1. Model A: , , . has no effect on .
Step 2. Model B: , . Effect of 1.
Step 3. Both give : identical observational distributions.
Step 4. is 0.5 in Model A and 1 in Model B.
Answer: data cannot distinguish the models, so no formula can recover the effect: it is not identified.
Part 3 · Applied
Exercise 11 · A tax credit and labour supply
An earned-income tax credit (eligibility depends on number of children ) affects hours worked ; children also affect hours directly. Graph: , , . Derive with the rules, naming each.
Show solution
Step 1. Condition and sum: .
Step 2. Rule 3: in the arrow is gone; paths –: , collider: blocked. So .
Step 3. Rule 2: in , paths –: , blocked by . So .
Answer: : compare hours of eligible and ineligible families with the same number of children, and average over the distribution of family size.
Exercise 12 · Effects within subgroups
In Exercise 11's graph plus a pre-treatment region indicator (, ), derive the region-specific effect .
Show solution
Step 1. Condition and sum within region: .
Step 2. Rule 3 (with ): in , paths – go through the collider ( or ), unconditioned: blocked. So .
Step 3. Rule 2: in , back-door paths and are blocked by . So .
Answer: , a conditional (CATE-type) version of the adjustment formula.
Exercise 13 · Two rounds of HIV treatment
A clinic decides treatment at the first visit; CD4 count is measured; treatment is decided at the second visit based on ; viral suppression is measured. Graph: , , , , , ( = unobserved health status); is randomised. Derive .
Show solution
Step 1. Condition on and sum: .
Step 2. Rule 3 removes from the second factor: is not an ancestor of . Then Rule 2 turns into : has no back-door paths. So .
Step 3. Rule 2 for in the first factor: in , back-door paths from (, ) are blocked by (and ). So it equals .
Step 4. Rule 2 for : in , has no remaining edges. So it equals .
Answer: the g-formula . Note that regressing on would be wrong: is a mediator for and a collider (). Day 96 develops this.
Exercise 14 · Ice cream and drowning
Hot weather raises ice-cream sales and swimming, hence drownings : , . A mayor proposes banning ice cream to cut drownings. Use Rule 3 to evaluate the proposal, and contrast with the observational association.
Show solution
Step 1. Rule 3: ? Removing isolates : d-separated.
Step 2. So : setting ice-cream sales to zero changes nothing.
Step 3. Observationally, rises with through the fork .
Answer: the ban would not reduce drownings; the association is pure confounding by weather.
Exercise 15 · A non-identified effect, numerically
A health economist has data only on insurance status and medical spending (both binary), with unobserved health affecting both. Build two SCMs matching , , , , one where insurance has no effect and one where it does.
Show solution
Step 1. Model A (no effect): let take four values that encode directly, with equal to the table; set , . The table is reproduced and does not depend on : for both .
Step 2. Model B (no confounding): and with uniform, , . Same table; causal effect .
Answer: both models fit the data perfectly; the effect could be 0 or 0.4. Without an admissible set, a front door or an instrument, the data are silent.
Verify in Python
import networkx as nx
dsep = getattr(nx, "is_d_separator", None) or nx.d_separated # name changed in networkx 3.3
def cut(G, into=(), out_of=()):
"""Remove arrows into the nodes in `into` and out of the nodes in `out_of`."""
H = G.copy()
H.remove_edges_from([e for e in G.edges if e[1] in into or e[0] in out_of])
return H
# Front-door graph (U explicit)
F = nx.DiGraph([("U", "X"), ("U", "Y"), ("X", "M"), ("M", "Y")])
print("Ex 7 rule 2:", dsep(cut(F, out_of={"X"}), {"M"}, {"X"}, set()))
print("Ex 8 rule 2:", dsep(cut(F, out_of={"M"}), {"Y"}, {"M"}, {"X"}), " rule 3:", dsep(cut(F, into={"M"}), {"X"}, {"M"}, set()))
print("Ex 9 rule 2:", dsep(cut(F, into={"X"}, out_of={"M"}), {"Y"}, {"M"}, {"X"}),
" rule 3:", dsep(cut(F, into={"X", "M"}), {"Y"}, {"X"}, {"M"}))
# Exercise 13: two rounds of treatment
H = nx.DiGraph([("X1", "L"), ("X1", "Y"), ("L", "X2"), ("X2", "Y"), ("U", "L"), ("U", "Y")])
print("Ex 13 rule 3 (X2 on L):", dsep(cut(H, into={"X2"}), {"L"}, {"X2"}, set()),
" rule 2 (X1 on L):", dsep(cut(H, out_of={"X1"}), {"L"}, {"X1"}, set()))
print(" rule 2 (X2 on Y):", dsep(cut(H, into={"X1"}, out_of={"X2"}), {"Y"}, {"X2"}, {"X1", "L"}),
" rule 2 (X1 on Y):", dsep(cut(H, out_of={"X1"}), {"Y"}, {"X1"}, {"X2", "L"}))
print(" naive regression on L is invalid for X1: L is a descendant of X1:", "L" in nx.descendants(H, "X1"))
# Exercise 15: two SCMs, same data, different effects
table = {(1, 1): .3, (1, 0): .2, (0, 1): .1, (0, 0): .4}
modelA = {x: sum(v for (xx, y), v in table.items() if y == 1) for x in (0, 1)} # Y ignores X
pX = {x: sum(v for (xx, y), v in table.items() if xx == x) for x in (0, 1)}
modelB = {x: table[x, 1] / pX[x] for x in (0, 1)}
print("P(Y=1|do(x)) model A:", modelA, " model B:", {k: round(v, 2) for k, v in modelB.items()})
Key takeaways
- Rule 1 adds or removes observations, Rule 2 swaps actions and observations, Rule 3 adds or removes actions; each needs a d-separation in a modified graph.
- The back-door and front-door formulas, and the g-formula for sequential treatments, are short derivations.
- The rules are complete: if no derivation exists, two models with the same data but different effects can be built.
Simulation Lab: do-Calculus, Step by Step
Open full screen →Walk through the back-door, front-door and g-formula derivations with each rule's d-separation checked in its modified graph.
Step through a derivation. For each step that uses a rule, the panel builds the modified graph the rule requires and checks the d-separation live. Conditioned nodes are grey; the two sets that must be separated are blue and green; U is unobserved.