Do-Calculus (p213)
![]() | ![]() |
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 gumimport pyagrum.lib.notebook as gnb
import pyagrum.causal as cslimport pyagrum.causal.notebook as cslnbthe causal diagram
Section titled “the causal diagram”The corresponding causal diagram is the following:
We’re facing the following situation and we want to measure the causal effect of on :
fd = gum.fastBN("w->z->x->y;w->x;w->y")fdWe suspect the presence of some unmeasured confounders, that could explain the correlation between and and between and :
fdModele = csl.CausalModel(fd, [("u1", ["w", "x"]), ("u2", ["w", "y"])], False)# (<latent variable name>, <list of affected variables’ ids>).gnb.show(fdModele)Even with two umeasured confounders :
Section titled “Even with two umeasured confounders :”
- We can measure the causal effect of on using the back-door adjustment:
print(" + Back-door doing Z on Y :" + str(fdModele.backDoor("z", "y"))) + Back-door doing Z on Y :{'w'}
- We can measure the causal effect of on using the front-door formula:
print(" + Front-door doing W on X :" + str(fdModele.frontDoor("w", "x"))) + Front-door doing W on X :{'z'}
- In order to measure the causal effect of on , 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 on is to use the do-calculus:
cslnb.showCausalImpact(fdModele, on="y", doing="x")|
|
| ||
|---|---|---|---|
|
| 0.3533 | 0.6467 | |
| 0.6584 | 0.3416 | ||
|
| 0.3571 | 0.6429 | |
| 0.6334 | 0.3666 | ||
