Type at least 2 letters. Enter opens the first result, Esc closes.

    Causal Inference · Lesson 4 · Causal graphs and the do-operator

    Interventions and identification: the do-operator, backdoor and frontdoor adjustment, do-calculus

    Advanced 90 min 5 interactive figures 5 videos Colab notebook

    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 P(y∣x)P(y \mid x), the second is P(y∣do(t),x)P(y \mid \mathrm{do}(t), x). 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 XX, drug TT, recovery YY, with the graph X→TX \to T, X→YX \to Y, T→YT \to Y. Severe patients (X=1X = 1) get the drug more often, and severity lowers recovery.

    • Seeing T=1T = 1: 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 T=1T = 1: we give the drug to everybody. Now severity no longer decides who is treated. In the graph, the arrow X→TX \to T is cut. The share of severe patients is the same as in the whole population.
    Interactive figure: loading…

    Switch between "seeing" and "doing", and move the slider "Severity → Drug" (the strength of that arrow). The magenta bars are what we see, P(Y=1∣T=t)P(Y = 1 \mid T = t); the aqua bars are the truth under intervention, P(Y=1∣do(T=t))P(Y = 1 \mid \mathrm{do}(T = t)). 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 (−0.04-0.04), although it raises recovery by 0.20.2. With strength 0 the two views agree.

    2.2 From surgery to a formula #

    The SCM of the figure factorizes as p(x,t,y)=p(x) p(t∣x) p(y∣t,x)p(x, t, y) = p(x)\,p(t \mid x)\,p(y \mid t, x). The surgery replaces the factor of TT by "T=tT = t with probability 1" and keeps the other factors:

    p(x,y∣do(t))=p(x) p(y∣t,x).p(x, y \mid \mathrm{do}(t)) = p(x)\, p(y \mid t, x).

    Sum over xx and compare with ordinary conditioning (law of total probability):

    P(y∣do(t))=∑xP(y∣t,x) P(x),P(y \mid \mathrm{do}(t)) = \sum_x P(y \mid t, x)\,\htmlClass{c3}{P(x)},
    P(y∣t)=∑xP(y∣t,x) P(x∣t).P(y \mid t) = \sum_x P(y \mid t, x)\,\htmlClass{c5}{P(x \mid t)}.

    The only difference is the weight of each severity group: the population share P(x)P(x) for doing, the share among the treated P(x∣t)P(x \mid t) for seeing. If TT did not depend on XX, the two would be equal.

    Numbers. In the figure P(Y=1∣T,X)=0.6+0.2T−0.4XP(Y = 1 \mid T, X) = 0.6 + 0.2T - 0.4X, P(X=1)=0.5P(X = 1) = 0.5, and with strength 0.60.6, P(X=1∣T=1)=0.8P(X = 1 \mid T = 1) = 0.8 and P(X=1∣T=0)=0.2P(X = 1 \mid T = 0) = 0.2.

    Doing uses the weights P(x)=(0.5,0.5)P(x) = (0.5, 0.5):

    P(Y=1∣do(T=1))=0.5⋅0.8+0.5⋅0.4=0.60,P(Y=1∣do(T=0))=0.5⋅0.6+0.5⋅0.2=0.40.\begin{aligned} P(Y{=}1 \mid \mathrm{do}(T{=}1)) &= 0.5 \cdot 0.8 + 0.5 \cdot 0.4 = 0.60, \\ P(Y{=}1 \mid \mathrm{do}(T{=}0)) &= 0.5 \cdot 0.6 + 0.5 \cdot 0.2 = 0.40 . \end{aligned}

    Seeing uses the weights P(x∣t)P(x \mid t):

    P(Y=1∣T=1)=0.2⋅0.8+0.8⋅0.4=0.48,P(Y=1∣T=0)=0.8⋅0.6+0.2⋅0.2=0.52.\begin{aligned} P(Y{=}1 \mid T{=}1) &= 0.2 \cdot 0.8 + 0.8 \cdot 0.4 = 0.48, \\ P(Y{=}1 \mid T{=}0) &= 0.8 \cdot 0.6 + 0.2 \cdot 0.2 = 0.52 . \end{aligned}

    In each sum, the first term is the mild group (X=0X = 0) and the second the severe group. Doing gives the effect 0.60−0.40=0.200.60 - 0.40 = 0.20; seeing gives 0.48−0.52=−0.040.48 - 0.52 = -0.04.

    Quick check

    Severity XX has P(X=1)=0.3P(X = 1) = 0.3. Recovery rates with the drug are 0.90.9 (mild) and 0.50.5 (severe). What is P(Y=1∣do(T=1))P(Y = 1 \mid \mathrm{do}(T = 1)) in the graph X→TX \to T, X→YX \to Y, T→YT \to Y?

    2.3 Which variables to adjust for #

    The formula of section 2.2 adjusts for XX. In a bigger graph, which set ZZ should we use? Lesson 03 gives the tool. Association between TT and YY flows along two kinds of paths:

    • causal paths T→⋯→YT \to \dots \to Y: they carry the effect; we must keep them open;
    • backdoor paths T←… YT \leftarrow \dots\, Y: they carry association that is not the effect; we must block them.

    A good set ZZ blocks every backdoor path, does not block causal paths, and opens no new path. The backdoor criterion of section 3.4 says exactly this.

    Interactive figure: loading…

    Click nodes to build the adjustment set ZZ (yellow). The panel lists the backdoor paths from the treatment TT to YY and says whether the set satisfies the backdoor criterion. Open backdoor paths are thick magenta, causal paths aqua. In the butterfly graph, try {X3}\{X_3\} (it opens X1→X3←X2X_1 \to X_3 \leftarrow X_2), then {X1,X3}\{X_1, X_3\}. In "mediator", see why MM must stay out.

    Quick check

    In the butterfly graph (X1→X3←X2X_1 \to X_3 \leftarrow X_2, X1→TX_1 \to T, X2→YX_2 \to Y, X3→TX_3 \to T, X3→YX_3 \to Y, T→YT \to Y), which set does not satisfy the backdoor criterion?

    3. Definitions and main results #

    3.1 Interventions #

    Definition (intervention). Let M\mathcal M be an SCM with graph GG. The intervention do(T=t)\mathrm{do}(T = t) gives a new SCM Mt\mathcal M_t: the assignment T:=fT(paT,UT)T := f_T(\mathrm{pa}_T, U_T) is replaced by T:=tT := t; all other assignments stay the same. Its graph is GT‾G_{\overline T}, the graph GG with all arrows into TT removed. The distribution of Mt\mathcal M_t is the interventional distribution P(⋅∣do(T=t))P(\cdot \mid \mathrm{do}(T = t)), short P(⋅∣do(t))P(\cdot \mid \mathrm{do}(t)).

    Two assumptions hide in this definition. Modularity: changing one assignment does not change the others (each mechanism is autonomous). Well-defined intervention: "set TT to tt" is something that could be done (lesson 02 called this consistency).

    Theorem (truncated factorization). If p(v)=∏jp(vj∣paj)p(v) = \prod_j p(v_j \mid \mathrm{pa}_j), then for every vv with T=tT = t,

    p(v∣do(t))=∏j: Vj≠Tp(vj∣paj)∣T=t,p(v \mid \mathrm{do}(t)) = \prod_{j:\, V_j \ne T} p(v_j \mid \mathrm{pa}_j)\Big|_{T = t},

    and p(v∣do(t))=0p(v \mid \mathrm{do}(t)) = 0 for vv with T≠tT \ne t.

    Proof. Mt\mathcal M_t has the same assignments, and so the same conditional distributions p(vj∣paj)p(v_j \mid \mathrm{pa}_j), for all Vj≠TV_j \ne T; its graph is GT‾G_{\overline T}, in which TT has no parents and the constant value tt. Apply the Markov factorization (lesson 03) to Mt\mathcal M_t. The factor of TT is 1 at T=tT = t and 0 elsewhere. ■\blacksquare

    The potential outcome Y(t)Y(t) of lesson 02 is the value of YY in the modified model Mt\mathcal M_t, with the same noises UU. So

    P(Y(t)=y)=P(y∣do(t)),τATE=E[Y∣do(T=1)]−E[Y∣do(T=0)].P(Y(t) = y) = P(y \mid \mathrm{do}(t)), \qquad \tau_{\mathrm{ATE}} = \mathbb{E}[Y \mid \mathrm{do}(T{=}1)] - \mathbb{E}[Y \mid \mathrm{do}(T{=}0)].

    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 ZZ satisfies the backdoor criterion of section 3.4, then conditional exchangeability holds, Y(t)⊥ ⁣ ⁣ ⁣⊥T∣ZY(t) \perp\!\!\!\perp T \mid Z. Intuition: Y(t)Y(t) is a function of the noises of YY and of the non-descendants of TT that matter; once ZZ blocks every backdoor path, nothing links those noises to the assignment of TT.

    3.3 Identification #

    Definition (identified). A causal quantity, such as P(y∣do(t))P(y \mid \mathrm{do}(t)), is identified from the graph GG if it is the same for every SCM with graph GG that gives the same observational distribution P(V)P(V) (with positive probabilities). Then it can be written as a formula in P(V)P(V) only.

    Identification is about infinite data. It asks "is the answer in the distribution at all?", not "how do I estimate it well from nn points?". Section 3.8 returns to estimation.

    Positivity. The formulas below divide by, or condition on, probabilities like P(t∣z)P(t \mid z). They need P(T=t∣Z=z)>0P(T = t \mid Z = z) > 0 for every zz with P(z)>0P(z) > 0: 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 ZZ of observed variables satisfies the backdoor criterion relative to (T,Y)(T, Y) if

    1. no node in ZZ is a descendant of TT; and
    2. ZZ blocks every path between TT and YY that starts with an arrow into TT (every backdoor path).

    Theorem (backdoor adjustment). If ZZ satisfies the backdoor criterion and positivity holds, then

    P(y∣do(t))=∑zP(y∣t,z) P(z).P(y \mid \mathrm{do}(t)) = \sum_z P(y \mid t, z)\, P(z).

    Why each condition is needed:

    • Condition 2 removes confounding: after conditioning on ZZ, the only open paths between TT and YY are causal.
    • Condition 1 stops two errors: a mediator in ZZ blocks part of the effect, and a descendant of TT that is also a collider (or a descendant of YY) opens a new path.

    Proof for Z=paTZ = \mathrm{pa}_T, the parents of TT.

    1. Truncated factorization: p(v∣do(t))=∏j: Vj≠Tp(vj∣paj)p(v \mid \mathrm{do}(t)) = \prod_{j:\, V_j \ne T} p(v_j \mid \mathrm{pa}_j) at T=tT = t.
    2. Multiply and divide by the missing factor p(t∣paT)p(t \mid \mathrm{pa}_T) (positive by positivity): p(v∣do(t))=p(v)/p(t∣paT)p(v \mid \mathrm{do}(t)) = p(v) / p(t \mid \mathrm{pa}_T), where vv includes T=tT = t.
    3. Sum over all variables except YY, TT (fixed at tt) and paT\mathrm{pa}_T. The denominator depends only on paT\mathrm{pa}_T, so it stays outside the sum, and the sum of p(v)p(v) gives p(y,t,paT)p(y, t, \mathrm{pa}_T). Then sum over paT\mathrm{pa}_T: P(y∣do(t))=∑paTp(y,t,paT)/p(t∣paT)P(y \mid \mathrm{do}(t)) = \sum_{\mathrm{pa}_T} p(y, t, \mathrm{pa}_T) / p(t \mid \mathrm{pa}_T).
    4. Write p(y,t,paT)=p(y∣t,paT) p(t∣paT) p(paT)p(y, t, \mathrm{pa}_T) = p(y \mid t, \mathrm{pa}_T)\, p(t \mid \mathrm{pa}_T)\, p(\mathrm{pa}_T) and cancel: P(y∣do(t))=∑paTp(y∣t,paT) p(paT)P(y \mid \mathrm{do}(t)) = \sum_{\mathrm{pa}_T} p(y \mid t, \mathrm{pa}_T)\, p(\mathrm{pa}_T). ■\blacksquare

    The parents of TT always satisfy the backdoor criterion (every backdoor path starts T←PT \leftarrow P with a parent PP as a non-collider). But parents are often unobserved, and other sets can work.

    Proof for a general backdoor set ZZ

    This proof uses rules 2 and 3 of do-calculus (section 3.7).

    1. Law of total probability in the intervened model: P(y∣do(t))=∑zP(y∣do(t),z) P(z∣do(t))P(y \mid \mathrm{do}(t)) = \sum_z P(y \mid \mathrm{do}(t), z)\, P(z \mid \mathrm{do}(t)).
    2. P(z∣do(t))=P(z)P(z \mid \mathrm{do}(t)) = P(z) by rule 3: in GT‾G_{\overline T}, TT has no parents, so every path from TT starts T→…T \to \dots. Such a path reaches a non-descendant of TT only after it turns against an arrow, at a collider. With an empty conditioning set the collider blocks. ZZ has no descendant of TT (condition 1), so (Z⊥ ⁣ ⁣ ⁣⊥T)GT‾(Z \perp\!\!\!\perp T)_{G_{\overline T}}.
    3. P(y∣do(t),z)=P(y∣t,z)P(y \mid \mathrm{do}(t), z) = P(y \mid t, z) by rule 2: in GT‾G_{\underline T} (arrows out of TT removed), the paths between TT and YY are exactly the backdoor paths of GG, and ZZ blocks them (condition 2). (A collider on such a path has the same descendants in ZZ in both graphs, because a node of ZZ reached only through TT would be a descendant of TT.) So (Y⊥ ⁣ ⁣ ⁣⊥T∣Z)GT‾(Y \perp\!\!\!\perp T \mid Z)_{G_{\underline T}}.
    4. Put steps 2 and 3 into step 1. ■\blacksquare

    Kidney stones again (lesson 01). Stone size SS affects the choice of treatment and the success: S→TS \to T, S→YS \to Y, T→YT \to Y. {S}\{S\} satisfies the backdoor criterion. With P(small)=357/700=0.51P(\text{small}) = 357/700 = 0.51:

    P(success∣do(A))=0.51⋅8187+0.49⋅192263=0.51⋅0.931+0.49⋅0.730=0.833,P(success∣do(B))=0.51⋅234270+0.49⋅5580=0.51⋅0.867+0.49⋅0.688=0.779.\begin{aligned} P(\text{success} \mid \mathrm{do}(A)) &= 0.51 \cdot \tfrac{81}{87} + 0.49 \cdot \tfrac{192}{263} = 0.51 \cdot 0.931 + 0.49 \cdot 0.730 = 0.833, \\ P(\text{success} \mid \mathrm{do}(B)) &= 0.51 \cdot \tfrac{234}{270} + 0.49 \cdot \tfrac{55}{80} = 0.51 \cdot 0.867 + 0.49 \cdot 0.688 = 0.779 . \end{aligned}

    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 P(y∣do(t))P(y \mid \mathrm{do}(t)) in the population, but different variances in a sample. A set that also contains causes of YY gives a more precise estimate; a set that contains strong causes of TT 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.

    Interactive figure: loading…

    Tick variables to add them to the regression of YY on TT. The readout gives the coefficient of TT 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 {X}\{X\}, {X,P}\{X, P\} and {X,Z}\{X, Z\} (same answer, different spread), then add MM, CC or MbMb. Hidden variables are dashed violet.

    The table gives the population value of the coefficient of TT, and its standard error for n=500n = 500, for the SCM of the figure:

    Adjustment set Coefficient of TT (n→∞n \to \infty) SE (n=500n = 500) Verdict
    {}\{\} (naive) 1.241.24 0.0500.050 bias: the backdoor path through XX is open
    {X}\{X\} (confounder) 1.001.00 0.0500.050 good: closes the backdoor path
    {X,P}\{X, P\} (cause of YY only) 1.001.00 0.0410.041 good: no bias, smaller SE
    {X,Z}\{X, Z\} (instrument) 1.001.00 0.0630.063 bad for precision: no bias, larger SE
    {Z}\{Z\} 1.351.35 0.0590.059 bad: bias grows from 0.240.24 to 0.350.35 (bias amplification)
    {X,M}\{X, M\} (mediator) 0.500.50 0.0910.091 bad: only the direct effect
    {X,C}\{X, C\} (collider of TT and YY) −0.53-0.53 0.0450.045 bad: strong bias, even the sign flips
    {X,Mb}\{X, Mb\} (M-bias node) 0.890.89 0.0490.049 bad: opens T←U1→Mb←U2→YT \leftarrow U_1 \to Mb \leftarrow U_2 \to Y

    How to read each row:

    • Confounder XX (T←X→YT \leftarrow X \to Y): adjust.
    • Precision variable PP (a cause of YY only): no backdoor path goes through it, so it does not change the bias. It explains part of the noise of YY, so the standard error goes down.
    • Instrument ZZ (a cause of TT only): it does not change the bias either, but it removes the part of the variation of TT that is "as good as random", so the standard error goes up. If a backdoor path stays open (here without XX), the remaining variation of TT is more confounded and the bias grows. Lesson 06 uses ZZ in a different, good way.
    • Mediator MM (T→M→YT \to M \to Y): a descendant of TT. Adjusting for it blocks part of the effect. You get the direct effect, a different estimand (lesson 09).
    • Collider CC (T→C←YT \to C \leftarrow Y; it is also a descendant of YY): adjusting for it opens a path and can destroy the answer. For the SCM Y=T+2X+εYY = T + 2X + \varepsilon_Y, C=T+Y+εCC = T + Y + \varepsilon_C with independent Gaussian noises of equal variance, the coefficient of TT given (X,C)(X, C) is exactly 0, because E[Y∣T,X,C]=X+C/2\mathbb{E}[Y \mid T, X, C] = X + C/2: given (T,X,C)(T, X, C) we know εY+εC=C−2T−2X\varepsilon_Y + \varepsilon_C = C - 2T - 2X, and we expect half of this sum to be εY\varepsilon_Y.
    • M-bias node MbMb: pre-treatment, but a collider on a backdoor path (lesson 03).
    • Proxy of a hidden confounder (not in the figure): a noisy measurement of UU. It closes the path only partly; adjusting usually reduces the bias but does not remove it.
    Quick check

    A colleague says: "ZZ strongly predicts who gets the treatment, so adding ZZ to the regression must reduce confounding." ZZ affects YY only through TT. What is correct?

    3.6 The frontdoor criterion #

    Sometimes the confounder is hidden and no backdoor set exists. Pearl's example: smoking TT affects cancer YY only through tar deposits MM, and a hidden genotype UU affects both smoking and cancer.

    Definition (frontdoor criterion; Pearl 1995). A set MM satisfies the frontdoor criterion relative to (T,Y)(T, Y) if

    1. MM intercepts every directed path from TT to YY (all of the effect goes through MM);
    2. there is no open backdoor path from TT to MM;
    3. every backdoor path from MM to YY is blocked by TT.

    Theorem (frontdoor adjustment). If MM satisfies the frontdoor criterion and positivity holds,

    P(y∣do(t))=∑mP(m∣t)∑t′P(y∣m,t′) P(t′).P(y \mid \mathrm{do}(t)) = \sum_m P(m \mid t) \sum_{t'} P(y \mid m, t')\, P(t').

    Derivation: two backdoor adjustments in a chain.

    1. Effect of TT on MM. By condition 2 there is no open backdoor path from TT to MM, so (backdoor with the empty set) P(m∣do(t))=P(m∣t)P(m \mid \mathrm{do}(t)) = P(m \mid t).
    2. Effect of MM on YY. The backdoor path M←T←U→YM \leftarrow T \leftarrow U \to Y is blocked by TT (condition 3), so {T}\{T\} is a backdoor set: P(y∣do(m))=∑t′P(y∣m,t′) P(t′)P(y \mid \mathrm{do}(m)) = \sum_{t'} P(y \mid m, t')\, P(t'). The sum is over all values t′t' of TT, weighted by the population share P(t′)P(t').
    3. Chain them. All of the effect of TT goes through MM (condition 1), and MM is not confounded with YY except through TT. So setting T=tT = t changes YY only by changing the distribution of MM: P(y∣do(t))=∑mP(m∣do(t)) P(y∣do(m))P(y \mid \mathrm{do}(t)) = \sum_m P(m \mid \mathrm{do}(t))\, P(y \mid \mathrm{do}(m)). Insert steps 1 and 2.

    The formal version of step 3 uses do-calculus; the folded block in section 3.7 goes through it.

    Interactive figure: loading…

    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 0.70−0.30=0.400.70 - 0.30 = 0.40 and the naive difference 0.580.58. 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).

    Quick check

    In the frontdoor example, P(T=1)=0.5P(T{=}1) = 0.5, P(M=1∣T=1)=0.9P(M{=}1 \mid T{=}1) = 0.9, P(M=1∣T=0)=0.1P(M{=}1 \mid T{=}0) = 0.1, and ∑t′P(Y=1∣m,t′)P(t′)\sum_{t'} P(Y{=}1 \mid m, t')P(t') equals 0.250.25 for m=0m = 0 and 0.750.75 for m=1m = 1. What is P(Y=1∣do(T=1))P(Y{=}1 \mid \mathrm{do}(T{=}1))?

    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 do\mathrm{do} into another. Each rule has a condition, a d-separation in a modified graph. Notation: X,Y,Z,WX, Y, Z, W are disjoint sets of nodes; GX‾G_{\overline X} removes the arrows into XX; GZ‾G_{\underline Z} removes the arrows out of ZZ.

    Rule 1 (insert or delete an observation). P(y∣do(x),z,w)=P(y∣do(x),w)P(y \mid \mathrm{do}(x), z, w) = P(y \mid \mathrm{do}(x), w) if (Y⊥ ⁣ ⁣ ⁣⊥Z∣X,W)GX‾(Y \perp\!\!\!\perp Z \mid X, W)_{G_{\overline X}}. In words: after the intervention, observing ZZ tells nothing more about YY. Example: in T→M→YT \to M \to Y, P(y∣do(m),t)=P(y∣do(m))P(y \mid \mathrm{do}(m), t) = P(y \mid \mathrm{do}(m)), because in GM‾G_{\overline M} the node TT is cut off from YY.

    Rule 2 (exchange an action and an observation). P(y∣do(x),do(z),w)=P(y∣do(x),z,w)P(y \mid \mathrm{do}(x), \mathrm{do}(z), w) = P(y \mid \mathrm{do}(x), z, w) if (Y⊥ ⁣ ⁣ ⁣⊥Z∣X,W)GX‾Z‾(Y \perp\!\!\!\perp Z \mid X, W)_{G_{\overline X \underline Z}}. In words: if, apart from its own effect, nothing links ZZ and YY (no open backdoor path), then setting ZZ and seeing ZZ are the same. Example: with no confounding (T→YT \to Y only), P(y∣do(t))=P(y∣t)P(y \mid \mathrm{do}(t)) = P(y \mid t).

    Rule 3 (insert or delete an action). P(y∣do(x),do(z),w)=P(y∣do(x),w)P(y \mid \mathrm{do}(x), \mathrm{do}(z), w) = P(y \mid \mathrm{do}(x), w) if (Y⊥ ⁣ ⁣ ⁣⊥Z∣X,W)GX‾ Z(W)‾(Y \perp\!\!\!\perp Z \mid X, W)_{G_{\overline X\, \overline{Z(W)}}}, where Z(W)Z(W) is the set of nodes of ZZ that are not ancestors of any node of WW in GX‾G_{\overline X}. In words: setting ZZ does not change YY when ZZ has no causal path to YY. Example: if Y→TY \to T (the outcome causes the "treatment"), P(y∣do(t))=P(y)P(y \mid \mathrm{do}(t)) = P(y).

    Completeness (Huang and Valtorta 2006; Shpitser and Pearl 2006). If P(y∣do(x))P(y \mid \mathrm{do}(x)) 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 do\mathrm{do}. 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: T←U→YT \leftarrow U \to Y, T→YT \to Y, with UU hidden. Two SCMs show that the data cannot decide. Let U∼Bernoulli(0.5)U \sim \mathrm{Bernoulli}(0.5) and T:=UT := U. In model 1, Y:=UY := U (the drug does nothing). In model 2, Y:=TY := T (the drug decides everything). Both give the same data: T=YT = Y always, each value with probability 0.50.5. But P(Y=1∣do(T=1))P(Y{=}1 \mid \mathrm{do}(T{=}1)) is 0.50.5 in model 1 and 11 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:

    1. P(y∣do(t))=∑mP(y∣do(t),m) P(m∣do(t))P(y \mid \mathrm{do}(t)) = \sum_m P(y \mid \mathrm{do}(t), m)\,P(m \mid \mathrm{do}(t)) (probability).
    2. P(m∣do(t))=P(m∣t)P(m \mid \mathrm{do}(t)) = P(m \mid t): rule 2, since (M⊥ ⁣ ⁣ ⁣⊥T)GT‾(M \perp\!\!\!\perp T)_{G_{\underline T}}.
    3. P(y∣do(t),m)=P(y∣do(t),do(m))P(y \mid \mathrm{do}(t), m) = P(y \mid \mathrm{do}(t), \mathrm{do}(m)): rule 2, since (Y⊥ ⁣ ⁣ ⁣⊥M∣T)GT‾M‾(Y \perp\!\!\!\perp M \mid T)_{G_{\overline T \underline M}}.
    4. P(y∣do(t),do(m))=P(y∣do(m))P(y \mid \mathrm{do}(t), \mathrm{do}(m)) = P(y \mid \mathrm{do}(m)): rule 3, since (Y⊥ ⁣ ⁣ ⁣⊥T∣M)GM‾ T‾(Y \perp\!\!\!\perp T \mid M)_{G_{\overline M\, \overline T}}.
    5. P(y∣do(m))=∑t′P(y∣do(m),t′) P(t′∣do(m))P(y \mid \mathrm{do}(m)) = \sum_{t'} P(y \mid \mathrm{do}(m), t')\,P(t' \mid \mathrm{do}(m)) (probability).
    6. P(t′∣do(m))=P(t′)P(t' \mid \mathrm{do}(m)) = P(t'): rule 3, since (T⊥ ⁣ ⁣ ⁣⊥M)GM‾(T \perp\!\!\!\perp M)_{G_{\overline M}}.
    7. P(y∣do(m),t′)=P(y∣m,t′)P(y \mid \mathrm{do}(m), t') = P(y \mid m, t'): rule 2, since (Y⊥ ⁣ ⁣ ⁣⊥M∣T)GM‾(Y \perp\!\!\!\perp M \mid T)_{G_{\underline M}}.
    8. Insert 2–7 into 1: the frontdoor formula.
    Interactive figure: loading…

    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 ∑zP(y∣t,z)P(z)\sum_z P(y \mid t, z) P(z) 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 (0.480.48 vs 0.520.52), although the drug raises recovery by 0.20.2: the treated are more often severe. (2) Worse. ZZ 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: X1→X3X_1 \to X_3, X2→X3X_2 \to X_3, X1→TX_1 \to T, X3→TX_3 \to T, X2→YX_2 \to Y, X3→YX_3 \to Y, T→YT \to Y. No XiX_i is a descendant of TT, so only condition 2 matters.

    Step 1: backdoor paths.

    • p1p_1: T←X3→YT \leftarrow X_3 \to Y (X3X_3 is a fork)
    • p2p_2: T←X1→X3→YT \leftarrow X_1 \to X_3 \to Y (X1X_1 fork, X3X_3 chain)
    • p3p_3: T←X3←X2→YT \leftarrow X_3 \leftarrow X_2 \to Y (X3X_3 chain, X2X_2 fork)
    • p4p_4: T←X1→X3←X2→YT \leftarrow X_1 \to X_3 \leftarrow X_2 \to Y (X1X_1 fork, X3X_3 collider, X2X_2 fork)

    Step 2: check the 8 subsets of {X1,X2,X3}\{X_1, X_2, X_3\}.

    • X3X_3 is a fork on p1p_1 and nothing else is on p1p_1, so every valid set contains X3X_3.
    • With X3X_3 in the set, p1,p2,p3p_1, p_2, p_3 are blocked at X3X_3, but p4p_4 opens at the collider X3X_3. It must be closed at X1X_1 or X2X_2.
    • Valid sets: {X1,X3}\{X_1, X_3\}, {X2,X3}\{X_2, X_3\}, {X1,X2,X3}\{X_1, X_2, X_3\}. Not valid: {}\{\}, {X1}\{X_1\}, {X2}\{X_2\}, {X1,X2}\{X_1, X_2\} (p1p_1 open), {X3}\{X_3\} (p4p_4 open).

    (b) The adjustment formula from a table. A study records sex XX, treatment TT and recovery YY, with graph X→TX \to T, X→YX \to Y, T→YT \to Y:

    P(X)P(X) P(Y=1∣T=1,X)P(Y{=}1 \mid T{=}1, X) P(Y=1∣T=0,X)P(Y{=}1 \mid T{=}0, X)
    X=0X = 0 0.60.6 0.70.7 0.50.5
    X=1X = 1 0.40.4 0.40.4 0.30.3
    P(Y=1∣do(T=1))=0.6⋅0.7+0.4⋅0.4=0.42+0.16=0.58,P(Y=1∣do(T=0))=0.6⋅0.5+0.4⋅0.3=0.30+0.12=0.42.\begin{aligned} P(Y{=}1 \mid \mathrm{do}(T{=}1)) &= 0.6 \cdot 0.7 + 0.4 \cdot 0.4 = 0.42 + 0.16 = 0.58, \\ P(Y{=}1 \mid \mathrm{do}(T{=}0)) &= 0.6 \cdot 0.5 + 0.4 \cdot 0.3 = 0.30 + 0.12 = 0.42 . \end{aligned}

    The average treatment effect is 0.58−0.42=0.160.58 - 0.42 = 0.16. Note that we never needed P(T∣X)P(T \mid X): 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: P(U=1)=0.5P(U{=}1) = 0.5, P(T=1∣U)=0.2P(T{=}1 \mid U) = 0.2 or 0.80.8, P(M=1∣T)=0.1P(M{=}1 \mid T) = 0.1 or 0.90.9, P(Y=1∣M,U)=0.1+0.5M+0.3UP(Y{=}1 \mid M, U) = 0.1 + 0.5M + 0.3U. The observational distribution (what infinite data show) gives P(T=1)=0.5P(T{=}1) = 0.5 and

    t′=0t' = 0 t′=1t' = 1
    P(Y=1∣M=0,t′)P(Y{=}1 \mid M{=}0, t') 0.160.16 0.340.34
    P(Y=1∣M=1,t′)P(Y{=}1 \mid M{=}1, t') 0.660.66 0.840.84

    (For example, P(U=1∣T=0)=0.5⋅0.2/(0.5⋅0.2+0.5⋅0.8)=0.2P(U{=}1 \mid T{=}0) = 0.5 \cdot 0.2 / (0.5 \cdot 0.2 + 0.5 \cdot 0.8) = 0.2, and MM does not depend on UU given TT, so P(Y=1∣M=0,T=0)=0.1+0.3⋅0.2=0.16P(Y{=}1 \mid M{=}0, T{=}0) = 0.1 + 0.3 \cdot 0.2 = 0.16.)

    Step 1. P(M=1∣T=1)=0.9P(M{=}1 \mid T{=}1) = 0.9, P(M=1∣T=0)=0.1P(M{=}1 \mid T{=}0) = 0.1.

    Step 2. ∑t′P(Y=1∣m,t′)P(t′)\sum_{t'} P(Y{=}1 \mid m, t')P(t'): for m=0m = 0, 0.5⋅0.16+0.5⋅0.34=0.250.5 \cdot 0.16 + 0.5 \cdot 0.34 = 0.25; for m=1m = 1, 0.5⋅0.66+0.5⋅0.84=0.750.5 \cdot 0.66 + 0.5 \cdot 0.84 = 0.75.

    Step 3. P(Y=1∣do(T=1))=0.1⋅0.25+0.9⋅0.75=0.70P(Y{=}1 \mid \mathrm{do}(T{=}1)) = 0.1 \cdot 0.25 + 0.9 \cdot 0.75 = 0.70 and P(Y=1∣do(T=0))=0.9⋅0.25+0.1⋅0.75=0.30P(Y{=}1 \mid \mathrm{do}(T{=}0)) = 0.9 \cdot 0.25 + 0.1 \cdot 0.75 = 0.30.

    The effect is 0.400.40. The truth from the hidden SCM is the same: P(Y=1∣do(T=1))=0.1+0.5⋅0.9+0.3⋅0.5=0.70P(Y{=}1 \mid \mathrm{do}(T{=}1)) = 0.1 + 0.5 \cdot 0.9 + 0.3 \cdot 0.5 = 0.70. The naive difference is P(Y=1∣T=1)−P(Y=1∣T=0)=0.79−0.21=0.58P(Y{=}1 \mid T{=}1) - P(Y{=}1 \mid T{=}0) = 0.79 - 0.21 = 0.58.

    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 TT 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 P(click∣do(show))P(\text{click} \mid \mathrm{do}(\text{show})); logged data give P(click∣show)P(\text{click} \mid \text{show}), 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 YY 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 TT (condition 1 fails). Check: was this variable fixed before the treatment was decided?
    • "Predicts the treatment strongly" = "confounder". A cause of TT only is an instrument; adjusting for it costs precision and can amplify bias. A confounder must also be linked to YY by a path that does not go through TT.
    • Writing P(y∣t)P(y \mid t) when you mean P(y∣do(t))P(y \mid \mathrm{do}(t)). 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 TT or YY, or if part of the effect bypasses it, the formula is biased with any amount of data.

    8. Check yourself #

    1. What does do(T=t)\mathrm{do}(T = t) change in an SCM, and what does it change in the graph?
      AnswerIt replaces the assignment of TT by the constant tt and keeps all other assignments. In the graph it removes every arrow into TT (graph GT‾G_{\overline T}).
    2. Graph: X→TX \to T, X→YX \to Y, T→M→YT \to M \to Y. Is {X,M}\{X, M\} a valid adjustment set for the total effect of TT on YY? Why?
      AnswerNo. MM is a descendant of TT (condition 1 fails). Adjusting for MM blocks the causal path T→M→YT \to M \to Y. {X}\{X\} alone is valid.
    3. Write the truncated factorization for the graph X→TX \to T, X→YX \to Y, T→YT \to Y, Y→SY \to S under do(t)\mathrm{do}(t).
      Answerp(x,y,s∣do(t))=p(x) p(y∣t,x) p(s∣y)p(x, y, s \mid \mathrm{do}(t)) = p(x)\,p(y \mid t, x)\,p(s \mid y): drop the factor p(t∣x)p(t \mid x) and put T=tT = t in the others.
    4. Why is the effect of TT on YY not identified in the graph T←U→YT \leftarrow U \to Y, T→YT \to Y with UU hidden?
      AnswerTwo SCMs with this graph give the same observational distribution but different P(y∣do(t))P(y \mid \mathrm{do}(t)), for example T:=UT := U with Y:=UY := U (no effect) or Y:=TY := T (full effect). A quantity that differs between models with the same data cannot be a function of the data.
    5. State the three conditions of the frontdoor criterion for a mediator MM.
      Answer(1) MM intercepts all directed paths from TT to YY; (2) no open backdoor path from TT to MM; (3) every backdoor path from MM to YY is blocked by TT.
    6. Two sets Z1Z_1 and Z2Z_2 both satisfy the backdoor criterion. Do the two adjusted estimates agree?
      AnswerIn the population, yes: both give P(y∣do(t))P(y \mid \mathrm{do}(t)). In a finite sample they differ by noise, and their variances differ: sets with causes of YY are more precise, sets with strong causes of TT less precise.
    Recall cardsAnswer in your head first, then reveal. Add the cards to your review deck to see them again just before you would forget.
    1. What does do(T=t)\mathrm{do}(T = t) do to the causal graph?

    2. Write the truncated factorization.

    3. State the two conditions of the backdoor criterion for a set ZZ.

    4. Write the backdoor adjustment formula.

    5. What is positivity, and why does the adjustment formula need it?

    6. Kidney stones: P(small)=0.51P(\text{small}) = 0.51; A succeeds in 93.1% (small) and 73.0% (large). What is P(success∣do(A))P(\text{success} \mid \mathrm{do}(A))?

    7. Why is adjusting for a mediator a bad control for the total effect?

    8. Why is an instrument a bad control?

    9. Write the frontdoor formula.

    10. What does completeness of do-calculus mean?

    Open the review →

    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 P(y∣x)P(y \mid x) and P(y∣do(x))P(y \mid \mathrm{do}(x))?" The first describes units that happen to have X=xX = x; the second describes what happens if we set X=xX = x 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:

    1. intervene(n, seed, do_t): simulate the SCM of section 2.1 with and without the intervention, and compare P(Y∣T)P(Y \mid T) with P(Y∣do(T))P(Y \mid \mathrm{do}(T)).
    2. 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.
    3. is_backdoor_set(parents, T, Y, Z) with the d-separation function of lesson 03 on GT‾G_{\underline T}; list all valid sets in the butterfly graph.
    4. Good and bad controls by simulation: the estimate and its standard deviation over 200 samples for each adjustment set of section 3.5.
    5. A frontdoor estimator on simulated discrete data with a hidden UU; compare with the truth 0.400.40 and the naive 0.580.58, then add the arrow U→MU \to M and watch it break.

    11. Watch and read #

    The backdoor criterion and the adjustment formula, with a proof from the truncated factorization.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    The frontdoor formula as two chained backdoor adjustments.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    The three rules and their graph conditions.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    Simulations of good and bad controls, including colliders and the "table 2 fallacy".
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    The ladder of causation and the do-operator, from the author of do-calculus.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play