Interventions and identification: the do-operator, backdoor and frontdoor adjustment, do-calculus
Before this lesson: lesson 03 (d-separation, backdoor paths, colliders) and lesson 02 (potential outcomes, exchangeability). From probability: the law of total probability with conditioning (probability 04). Time: about 90 minutes, plus the notebook.
Why this matters #
- Decisions need "doing". A churn model predicts who leaves; a retention team wants to know who leaves less when given a discount. The first question is , the second is . Most ML data are observational, so we need the conditions under which the second can be computed from the first kind of data.
- Choosing features for adjustment. Lessons 05 and 08 estimate effects with regression, matching, weighting and double ML. All of them adjust for a set of covariates, and all of them fail if the set is wrong. This lesson tells you which set is right.
- Bad controls are common. Adjusting for a post-treatment variable (a mediator), for a variable caused by the outcome, or for a pre-treatment collider gives biased answers even with infinite data.
- Identification before estimation. Libraries such as DoWhy and the ID algorithm in causal software first check identification with the rules of this lesson, then estimate.
1. Predict first #
2. The picture #
2.1 Seeing versus doing #
Take three binary variables: severity , drug , recovery , with the graph , , . Severe patients () get the drug more often, and severity lowers recovery.
- Seeing : we look at the patients who took the drug. Many of them are severe, because severity caused the treatment. Their recovery rate mixes the effect of the drug with the effect of severity.
- Doing : we give the drug to everybody. Now severity no longer decides who is treated. In the graph, the arrow is cut. The share of severe patients is the same as in the whole population.
Switch between "seeing" and "doing", and move the slider "Severity → Drug" (the strength of that arrow). The magenta bars are what we see, ; the aqua bars are the truth under intervention, . In the doing view the arrow into the drug is cut and the share of severe patients stays at 0.5. With strength 0.6 the drug looks slightly harmful when we only see (), although it raises recovery by . With strength 0 the two views agree.
2.2 From surgery to a formula #
The SCM of the figure factorizes as . The surgery replaces the factor of by " with probability 1" and keeps the other factors:
Sum over and compare with ordinary conditioning (law of total probability):
The only difference is the weight of each severity group: the population share for doing, the share among the treated for seeing. If did not depend on , the two would be equal.
Numbers. In the figure , , and with strength , and .
Doing uses the weights :
Seeing uses the weights :
In each sum, the first term is the mild group () and the second the severe group. Doing gives the effect ; seeing gives .
Severity has . Recovery rates with the drug are (mild) and (severe). What is in the graph , , ?
Doing keeps the population mix of severity: . is what you need for seeing, not for doing. The plain average ignores the weights; swaps them.
2.3 Which variables to adjust for #
The formula of section 2.2 adjusts for . In a bigger graph, which set should we use? Lesson 03 gives the tool. Association between and flows along two kinds of paths:
- causal paths : they carry the effect; we must keep them open;
- backdoor paths : they carry association that is not the effect; we must block them.
A good set blocks every backdoor path, does not block causal paths, and opens no new path. The backdoor criterion of section 3.4 says exactly this.
Click nodes to build the adjustment set (yellow). The panel lists the backdoor paths from the treatment to and says whether the set satisfies the backdoor criterion. Open backdoor paths are thick magenta, causal paths aqua. In the butterfly graph, try (it opens ), then . In "mediator", see why must stay out.
In the butterfly graph (, , , , , ), which set does not satisfy the backdoor criterion?
The path is a backdoor path with a fork at , so must be in the set. alone is not enough either: is a collider on , so it opens that path, and or must close it again.
3. Definitions and main results #
3.1 Interventions #
Definition (intervention). Let be an SCM with graph . The intervention gives a new SCM : the assignment is replaced by ; all other assignments stay the same. Its graph is , the graph with all arrows into removed. The distribution of is the interventional distribution , short .
Two assumptions hide in this definition. Modularity: changing one assignment does not change the others (each mechanism is autonomous). Well-defined intervention: "set to " is something that could be done (lesson 02 called this consistency).
Theorem (truncated factorization). If , then for every with ,
and for with .
Proof. has the same assignments, and so the same conditional distributions , for all ; its graph is , in which has no parents and the constant value . Apply the Markov factorization (lesson 03) to . The factor of is 1 at and 0 elsewhere.
3.2 The link to potential outcomes #
The potential outcome of lesson 02 is the value of in the modified model , with the same noises . So
The two languages describe the same objects. Graphs make the assumptions visible; potential outcomes make the estimands precise. A useful bridge (Pearl 2009, ch. 11): if a set satisfies the backdoor criterion of section 3.4, then conditional exchangeability holds, . Intuition: is a function of the noises of and of the non-descendants of that matter; once blocks every backdoor path, nothing links those noises to the assignment of .
3.3 Identification #
Definition (identified). A causal quantity, such as , is identified from the graph if it is the same for every SCM with graph that gives the same observational distribution (with positive probabilities). Then it can be written as a formula in only.
Identification is about infinite data. It asks "is the answer in the distribution at all?", not "how do I estimate it well from points?". Section 3.8 returns to estimation.
Positivity. The formulas below divide by, or condition on, probabilities like . They need for every with : in every group, some units get each treatment value. Positivity can be checked with data (lesson 05 shows how).
3.4 The backdoor criterion and the adjustment formula #
Definition (backdoor criterion; Pearl 1993). A set of observed variables satisfies the backdoor criterion relative to if
- no node in is a descendant of ; and
- blocks every path between and that starts with an arrow into (every backdoor path).
Theorem (backdoor adjustment). If satisfies the backdoor criterion and positivity holds, then
Why each condition is needed:
- Condition 2 removes confounding: after conditioning on , the only open paths between and are causal.
- Condition 1 stops two errors: a mediator in blocks part of the effect, and a descendant of that is also a collider (or a descendant of ) opens a new path.
Proof for , the parents of .
- Truncated factorization: at .
- Multiply and divide by the missing factor (positive by positivity): , where includes .
- Sum over all variables except , (fixed at ) and . The denominator depends only on , so it stays outside the sum, and the sum of gives . Then sum over : .
- Write and cancel: .
The parents of always satisfy the backdoor criterion (every backdoor path starts with a parent as a non-collider). But parents are often unobserved, and other sets can work.
Proof for a general backdoor set
This proof uses rules 2 and 3 of do-calculus (section 3.7).
- Law of total probability in the intervened model: .
- by rule 3: in , has no parents, so every path from starts . Such a path reaches a non-descendant of only after it turns against an arrow, at a collider. With an empty conditioning set the collider blocks. has no descendant of (condition 1), so .
- by rule 2: in (arrows out of removed), the paths between and are exactly the backdoor paths of , and blocks them (condition 2). (A collider on such a path has the same descendants in in both graphs, because a node of reached only through would be a descendant of .) So .
- Put steps 2 and 3 into step 1.
Kidney stones again (lesson 01). Stone size affects the choice of treatment and the success: , , . satisfies the backdoor criterion. With :
Treatment A is better by about 5 percentage points, although the pooled rates (78.0% vs 82.6%) say the opposite. The adjustment formula is the "standardized rate" of lesson 01, now with a reason.
Several valid sets. Different sets can satisfy the criterion. They all give the same in the population, but different variances in a sample. A set that also contains causes of gives a more precise estimate; a set that contains strong causes of gives a less precise one.
3.5 Good and bad controls #
Cinelli, Forney and Pearl (2022) sort candidate controls by their position in the graph. The next figure puts six of them in one linear SCM with a true total effect of 1.
Tick variables to add them to the regression of on . The readout gives the coefficient of with its standard error, its value with infinite data, the truth (1) and the naive estimate. Press "Run 200 samples" to see the spread of the estimate for the current set. Compare , and (same answer, different spread), then add , or . Hidden variables are dashed violet.
The table gives the population value of the coefficient of , and its standard error for , for the SCM of the figure:
| Adjustment set | Coefficient of () | SE () | Verdict |
|---|---|---|---|
| (naive) | bias: the backdoor path through is open | ||
| (confounder) | good: closes the backdoor path | ||
| (cause of only) | good: no bias, smaller SE | ||
| (instrument) | bad for precision: no bias, larger SE | ||
| bad: bias grows from to (bias amplification) | |||
| (mediator) | bad: only the direct effect | ||
| (collider of and ) | bad: strong bias, even the sign flips | ||
| (M-bias node) | bad: opens |
How to read each row:
- Confounder (): adjust.
- Precision variable (a cause of only): no backdoor path goes through it, so it does not change the bias. It explains part of the noise of , so the standard error goes down.
- Instrument (a cause of only): it does not change the bias either, but it removes the part of the variation of that is "as good as random", so the standard error goes up. If a backdoor path stays open (here without ), the remaining variation of is more confounded and the bias grows. Lesson 06 uses in a different, good way.
- Mediator (): a descendant of . Adjusting for it blocks part of the effect. You get the direct effect, a different estimand (lesson 09).
- Collider (; it is also a descendant of ): adjusting for it opens a path and can destroy the answer. For the SCM , with independent Gaussian noises of equal variance, the coefficient of given is exactly 0, because : given we know , and we expect half of this sum to be .
- M-bias node : pre-treatment, but a collider on a backdoor path (lesson 03).
- Proxy of a hidden confounder (not in the figure): a noisy measurement of . It closes the path only partly; adjusting usually reduces the bias but does not remove it.
A colleague says: " strongly predicts who gets the treatment, so adding to the regression must reduce confounding." affects only through . What is correct?
A confounder must cause both and (or lie on a backdoor path). is on no backdoor path, so it cannot remove bias. It explains variation of that is unconfounded, so the remaining variation is noisier (larger SE) and, if a backdoor path is still open, relatively more confounded (bias amplification: in the table).
3.6 The frontdoor criterion #
Sometimes the confounder is hidden and no backdoor set exists. Pearl's example: smoking affects cancer only through tar deposits , and a hidden genotype affects both smoking and cancer.
Definition (frontdoor criterion; Pearl 1995). A set satisfies the frontdoor criterion relative to if
- intercepts every directed path from to (all of the effect goes through );
- there is no open backdoor path from to ;
- every backdoor path from to is blocked by .
Theorem (frontdoor adjustment). If satisfies the frontdoor criterion and positivity holds,
Derivation: two backdoor adjustments in a chain.
- Effect of on . By condition 2 there is no open backdoor path from to , so (backdoor with the empty set) .
- Effect of on . The backdoor path is blocked by (condition 3), so is a backdoor set: . The sum is over all values of , weighted by the population share .
- Chain them. All of the effect of goes through (condition 1), and is not confounded with except through . So setting changes only by changing the distribution of : . Insert steps 1 and 2.
The formal version of step 3 uses do-calculus; the folded block in section 3.7 goes through it.
Move the sliders, then press "Add the arrow U → Tar". The data are a sample of 20,000 people with smoking, tar and cancer; the genotype is never in the data. The table computes the frontdoor formula step by step from the sample. Compare the estimate (ink) with the truth from the hidden model and with the naive difference. With the default numbers the truth is and the naive difference . With the arrow U → Tar, condition 2 fails and the formula is biased even with infinite data.
How often does the frontdoor work in practice? Rarely in a clean form. It needs a mediator that carries all of the effect and that shares no hidden cause with the treatment or with the outcome. Real tar deposits are probably affected by the genotype too. The frontdoor idea is still useful as a check, and in settings where a mechanism is fully measured (for example an ad that can only act through a click, or a policy that acts only through an eligibility status).
In the frontdoor example, , , , and equals for and for . What is ?
. is the naive , which mixes in the hidden genotype. forgets that 10% of smokers have no tar.
3.7 Do-calculus #
The backdoor and frontdoor formulas are special cases. Pearl's do-calculus (1995) has three rules that change one expression with into another. Each rule has a condition, a d-separation in a modified graph. Notation: are disjoint sets of nodes; removes the arrows into ; removes the arrows out of .
Rule 1 (insert or delete an observation). if . In words: after the intervention, observing tells nothing more about . Example: in , , because in the node is cut off from .
Rule 2 (exchange an action and an observation). if . In words: if, apart from its own effect, nothing links and (no open backdoor path), then setting and seeing are the same. Example: with no confounding ( only), .
Rule 3 (insert or delete an action). if , where is the set of nodes of that are not ancestors of any node of in . In words: setting does not change when has no causal path to . Example: if (the outcome causes the "treatment"), .
Completeness (Huang and Valtorta 2006; Shpitser and Pearl 2006). If is identified in a graph with hidden variables, then a finite sequence of the three rules (and the rules of probability) derives a formula without . The ID algorithm finds such a formula or proves that none exists. So "the rules cannot do it" means "no method can do it" with this graph and no further assumptions.
An effect that is not identified: the bow-tie. Graph: , , with hidden. Two SCMs show that the data cannot decide. Let and . In model 1, (the drug does nothing). In model 2, (the drug decides everything). Both give the same data: always, each value with probability . But is in model 1 and in model 2. No formula in the observational distribution can give both answers. To make progress you need more: a measured confounder, an instrument (lesson 06), a frontdoor mediator, or bounds and sensitivity analysis (lesson 05).
The frontdoor formula, derived with the three rules
The figure after this block steps through the same derivation. In symbols:
- (probability).
- : rule 2, since .
- : rule 2, since .
- : rule 3, since .
- (probability).
- : rule 3, since .
- : rule 2, since .
- Insert 2–7 into 1: the frontdoor formula.
Optional. Press "Next step" to go through the derivation, then add the arrow U → M and go through it again. For each step the figure draws the modified graph that the rule needs (removed edges faded, with ✕), the conditioning set (yellow) and the result of the d-separation test. Open paths that make a test fail are thick magenta. With U → M, steps 2, 3 and 7 fail, so the rules cannot derive the formula.
3.8 From identification to estimation #
An identification formula such as is a statistical estimand: a property of the observational distribution. To use it with data we need an estimator. With few discrete covariates, plug in the sample frequencies (this lesson's notebook). With many or continuous covariates, use regression, matching, inverse probability weighting or doubly robust methods (lesson 05) or ML-based estimators (lesson 08). The graph decides what to estimate; statistics decides how well.
Answers to section 1. (1) Yes. With strength 0.6 in section 2.1, the drug group recovers less often ( vs ), although the drug raises recovery by : the treated are more often severe. (2) Worse. is an instrument: it removes no bias, increases the variance, and amplifies any remaining bias. (3) Yes, if tar carries the whole effect and shares no hidden cause with smoking or with cancer: the frontdoor formula.
4. Worked example #
(a) All valid adjustment sets in the butterfly graph. Edges: , , , , , , . No is a descendant of , so only condition 2 matters.
Step 1: backdoor paths.
- : ( is a fork)
- : ( fork, chain)
- : ( chain, fork)
- : ( fork, collider, fork)
Step 2: check the 8 subsets of .
- is a fork on and nothing else is on , so every valid set contains .
- With in the set, are blocked at , but opens at the collider . It must be closed at or .
- Valid sets: , , . Not valid: , , , ( open), ( open).
(b) The adjustment formula from a table. A study records sex , treatment and recovery , with graph , , :
The average treatment effect is . Note that we never needed : it matters for seeing, not for doing (it matters for estimation, through positivity and variance).
(c) The frontdoor formula with numbers. Use the SCM of the frontdoor figure: , or , or , . The observational distribution (what infinite data show) gives and
(For example, , and does not depend on given , so .)
Step 1. , .
Step 2. : for , ; for , .
Step 3. and .
The effect is . The truth from the hidden SCM is the same: . The naive difference is .
5. In code #
The code checks the kidney-stone adjustment and the frontdoor example. The truth is computed by simulating the intervention: run the SCM again with set by hand.
import numpy as np
# (1) kidney stones: backdoor adjustment over stone size (Charig et al. 1986)
success = {"A": {"small": (81, 87), "large": (192, 263)},
"B": {"small": (234, 270), "large": (55, 80)}}
p_small = (87 + 270) / 700
for t, d in success.items():
pooled = sum(s for s, n in d.values()) / sum(n for s, n in d.values())
adjusted = (p_small * d["small"][0] / d["small"][1]
+ (1 - p_small) * d["large"][0] / d["large"][1])
print(t, round(pooled, 3), round(adjusted, 3))
# A 0.78 0.833
# B 0.826 0.779
# (2) frontdoor: hidden genotype U, smoking T, tar M, cancer Y
def simulate(n, seed, do_t=None):
rng = np.random.default_rng(seed)
U = rng.random(n) < 0.5
T = rng.random(n) < np.where(U, 0.8, 0.2) if do_t is None else np.full(n, bool(do_t))
M = rng.random(n) < np.where(T, 0.9, 0.1)
Y = rng.random(n) < 0.1 + 0.5 * M + 0.3 * U
return T.astype(int), M.astype(int), Y.astype(int)
T, M, Y = simulate(1_000_000, seed=0) # observational data; U is not returned
def frontdoor(T, M, Y, t):
pt = {tp: (T == tp).mean() for tp in (0, 1)}
total = 0.0
for m in (0, 1):
p_m_t = (M[T == t] == m).mean() # step 1
inner = sum(Y[(M == m) & (T == tp)].mean() * pt[tp] for tp in (0, 1)) # step 2
total += p_m_t * inner # step 3
return total
naive = Y[T == 1].mean() - Y[T == 0].mean()
fd = frontdoor(T, M, Y, 1) - frontdoor(T, M, Y, 0)
truth = simulate(1_000_000, 1, do_t=1)[2].mean() - simulate(1_000_000, 2, do_t=0)[2].mean()
print(f"naive {naive:.3f} frontdoor {fd:.3f} truth by intervention {truth:.3f}")
# naive 0.580 frontdoor 0.400 truth by intervention 0.400
6. Where it shows up #
- Observational studies in medicine and economics. Analysts draw the DAG, find a backdoor set, check positivity, and then estimate (lessons 05, 08). Target-trial emulation (Hernán and Robins) is this workflow with careful time ordering.
- Product and marketing analytics. "Did the discount increase retention?" when the discount was given by a rule or by sales staff. The variables that the rule used are the backdoor set; variables measured after the discount (sessions, support tickets) are mediators or colliders and must stay out.
- Recommender systems and ads. The effect of showing an item is ; logged data give , confounded by the old policy's features. Off-policy evaluation (lesson 11) is backdoor adjustment over those features.
- Fairness. Path-specific and counterfactual fairness definitions are statements about interventions on a causal graph (lesson 09).
- ML for science. In Earth-system and biomedical data, interventions are often impossible (climate) or expensive (gene knockouts). Identification from graphs tells which observational comparisons answer an interventional question, and which need an experiment.
7. Common mistakes #
- "Adjust for every variable you have." Mediators, colliders, descendants of and M-bias nodes create bias. Check: draw the graph and test the backdoor criterion for the set.
- Adjusting for a variable measured after treatment. It is often a descendant of (condition 1 fails). Check: was this variable fixed before the treatment was decided?
- "Predicts the treatment strongly" = "confounder". A cause of only is an instrument; adjusting for it costs precision and can amplify bias. A confounder must also be linked to by a path that does not go through .
- Writing when you mean . They are equal only when there is no open backdoor path. Check: list the backdoor paths.
- Mixing identification and estimation. "The effect is identified" says nothing about the sample size needed; "the estimate is significant" says nothing about whether it estimates the right quantity.
- Using the frontdoor formula without checking its conditions. If the mediator shares a hidden cause with or , or if part of the effect bypasses it, the formula is biased with any amount of data.
8. Check yourself #
- What does change in an SCM, and what does it change in the graph?
Answer
It replaces the assignment of by the constant and keeps all other assignments. In the graph it removes every arrow into (graph ). - Graph: , , . Is a valid adjustment set for the total
effect of on ? Why?
Answer
No. is a descendant of (condition 1 fails). Adjusting for blocks the causal path . alone is valid. - Write the truncated factorization for the graph , , , under
.
Answer
: drop the factor and put in the others. - Why is the effect of on not identified in the graph , with
hidden?
Answer
Two SCMs with this graph give the same observational distribution but different , for example with (no effect) or (full effect). A quantity that differs between models with the same data cannot be a function of the data. - State the three conditions of the frontdoor criterion for a mediator .
Answer
(1) intercepts all directed paths from to ; (2) no open backdoor path from to ; (3) every backdoor path from to is blocked by . - Two sets and both satisfy the backdoor criterion. Do the two adjusted estimates agree?
Answer
In the population, yes: both give . In a finite sample they differ by noise, and their variances differ: sets with causes of are more precise, sets with strong causes of less precise.
What does do to the causal graph?
It removes every arrow into (graph ) and fixes ; all other mechanisms stay the same.
Write the truncated factorization.
, evaluated at .
State the two conditions of the backdoor criterion for a set .
(1) No node of is a descendant of . (2) blocks every path between and that starts with an arrow into .
Write the backdoor adjustment formula.
.
What is positivity, and why does the adjustment formula need it?
whenever . Without it, is undefined for some groups.
Kidney stones: ; A succeeds in 93.1% (small) and 73.0% (large). What is ?
.
Why is adjusting for a mediator a bad control for the total effect?
The mediator is a descendant of ; conditioning on it blocks the causal path through it, so you estimate only the direct effect.
Why is an instrument a bad control?
It is on no backdoor path, so it removes no bias; it removes clean variation of , so the variance grows, and any remaining bias is amplified.
Write the frontdoor formula.
.
What does completeness of do-calculus mean?
If an interventional distribution is identified from the graph, the three rules (with probability rules) can derive its formula; if they cannot, no method can without more assumptions.
9. Interview angle #
- "Which variables would you control for to estimate the effect of a discount on retention?" Draw the graph first. Control for the variables that decided who got the discount and that also affect retention (tenure, past spend, plan type), measured before the discount. Do not control for post-discount behavior (sessions, purchases), which are mediators, or for anything caused by retention.
- "What is the difference between and ?" The first describes units that happen to have ; the second describes what happens if we set for everybody. They differ when a backdoor path is open, as with sicker patients getting a stronger drug.
- "Is more control always better in a regression for causal effects?" No. Give the mediator, the collider and the instrument examples, each with its graph.
- "The confounder is not measured. Is all hope lost?" Not always: a frontdoor mediator, an instrument (lesson 06), a design such as regression discontinuity or difference-in-differences (lesson 07), or a sensitivity analysis (lesson 05). In the bow-tie graph with nothing else, the effect is not identified.
10. Practice #
The notebook for this lesson has five exercises, each with a check cell and a folded solution:
intervene(n, seed, do_t): simulate the SCM of section 2.1 with and without the intervention, and compare with .backdoor_adjust(df, t, y, Z): the plug-in adjustment formula for discrete data; check it on the kidney-stone counts and on a simulated SCM.is_backdoor_set(parents, T, Y, Z)with the d-separation function of lesson 03 on ; list all valid sets in the butterfly graph.- Good and bad controls by simulation: the estimate and its standard deviation over 200 samples for each adjustment set of section 3.5.
- A frontdoor estimator on simulated discrete data with a hidden ; compare with the truth and the naive , then add the arrow and watch it break.
11. Watch and read #
- Judea Pearl, Madelyn Glymour and Nicholas Jewell, Causal Inference in Statistics: A Primer (Wiley 2016), ch. 3 (interventions, backdoor, frontdoor); companion site.
- Carlos Cinelli, Andrew Forney and Judea Pearl, "A Crash Course in Good and Bad Controls", Sociological Methods & Research (2022).
- Brady Neal, Introduction to Causal Inference, free course notes, ch. 4 (do-operator, backdoor) and ch. 6 (frontdoor, do-calculus).
- Judea Pearl, "Causal diagrams for empirical research", Biometrika 82 (1995): the original do-calculus and frontdoor paper.
- Ilya Shpitser and Judea Pearl, "Identification of joint interventional distributions in recursive semi-Markovian causal models", AAAI 2006: the ID algorithm and completeness.
Runs in your browser with nothing to install. The notebook repeats the key demos and has exercises with checks; solutions are inside, folded.
No Google account needed: Python runs inside your browser. The first start downloads about 40 MB; your changes are saved in this browser only.