Skip to content

Do-Calculus (p213)

Creative Commons LicenseaGrUMinteractive online version

Authors: Aymen Merrouche and Pierre-Henri Wuillemin.

This notebook follows the example from “The Book Of Why” (Pearl, 2018) chapter 7 page 213

import pyagrum as gum
import pyagrum.lib.notebook as gnb

The corresponding causal diagram is the following:

We’re facing the following situation and we want to measure the causal effect of XX on YY:

fd = gum.fastBN("w->z->x->y;w->x;w->y")
fd
G w w y y w->y x x w->x z z w->z x->y z->x

We suspect the presence of some unmeasured confounders, that could explain the correlation between WW and XX and between WW and YY:

fdModele = gum.CausalModel(fd, [("u1", ["w", "x"]), ("u2", ["w", "y"])], False)
# (<latent variable name>, <list of affected variables’ ids>).
gnb.show(fdModele)

svg

  • We can measure the causal effect of ZZ on YY using the back-door adjustment:
print(" + Back-door doing Z on Y :" + str(fdModele.backDoor("z", "y")))
+ Back-door doing Z on Y :{0}
  • We can measure the causal effect of WW on XX using the front-door formula:
print(" + Front-door doing W on X :" + str(fdModele.frontDoor("w", "x")))
+ Front-door doing W on X :{1}
  • In order to measure the causal effect of XX on YY, we can use neither the back-door adjustment nor the front-door formula:
print(" + Backdoor doing X on Y :" + str(fdModele.backDoor("x", "y")))
print(" + Frontdoor doing X on Y :" + str(fdModele.frontDoor("x", "y")))
+ Backdoor doing X on Y :None
+ Frontdoor doing X on Y :None
  • In this case, the only way to measure the causal effect of XX on YY is to use the do-calculus:
gnb.showCausalImpact(fdModele, on="y", doing="x")
u1 w w u1->w x x u1->x u2 u2->w y y u2->y z z w->z z->x x->y
Causal Model
P(ydo(x))=wP(yw,x)P(xw,z)P(w)w,yP(yw,x)P(xw,z)P(w)\begin{equation*}P\left(y \mid \text{do}(x)\right) = \frac {\sum_{w}{P\left(y\mid w,x\right) \cdot P\left(x\mid w,z\right) \cdot P\left(w\right)}}{\sum_{w,y'}{P\left(y'\mid w,x\right) \cdot P\left(x\mid w,z\right) \cdot P\left(w\right)}}\end{equation*}


Explanation : Identified via do-calculus (ID/IDC).

x
y
z
0
1
0
0
0.32360.5246
1
0.20200.5021
1
0
0.67640.4754
1
0.79800.4979

Impact