- Author: Ayushman Saini
- Project Type: Foundational Causal Inference & Structural Causal Modeling (SCM)
-
Objective: To demonstrate the difference between statistical association
$P(Y\mid X)$ and causal intervention$P(Y\mid do(X))$ using a hand-calculated 3-node graph with a hidden confounder and the Backdoor Adjustment Formula.
Most modern AI systems learn from passive observation. They discover statistical associations in data, but they do not by themselves distinguish whether
This project constructs a compact structural universe with a hidden confounder and verifies Pearl's Backdoor Adjustment Formula entirely by hand. The result is a polished, academic-style causal analysis that demonstrates how observational probabilities can be misleading, while the interventional distribution recovers the true causal effect.
We study a simple causal universe defined by three binary variables:
-
$X$ (Treatment / Exposure): Training Mode-
$X = 1$ : High-Tech Exo-Suit -
$X = 0$ : Organic training
-
-
$Y$ (Outcome / Effect): Battle Result-
$Y = 1$ : Victory -
$Y = 0$ : Defeat
-
-
$Z$ (Confounder): Innate Power Class-
$Z = 1$ : Metahuman / God-like power -
$Z = 0$ : Street-level / non-powered human
-
Metahumans rarely use suits and still win most battles. Street-level heroes use suits more often, but they have lower base win rates. This creates a classic selection bias: the treatment
The dataset contains 20 hero battle records. Each row is a historical observation of
| Hero ID | Power Class ( |
Training Mode ( |
Battle Outcome ( |
Narrative Context |
|---|---|---|---|---|
| 1 | 1 | 0 | 1 | Kryptonian / Flight |
| 2 | 1 | 0 | 1 | Amazonian Demi-God |
| 3 | 1 | 0 | 1 | Atlantean Royalty |
| 4 | 1 | 0 | 1 | Cosmic Sorcerer |
| 5 | 1 | 0 | 1 | Speedster |
| 6 | 1 | 0 | 1 | Alien Mutant |
| 7 | 1 | 1 | 1 | Thunder God / Armor trial |
| 8 | 1 | 1 | 1 | Energy Manipulator |
| 9 | 0 | 0 | 1 | Martial Arts Master |
| 10 | 0 | 0 | 0 | Vigilante Archer |
| 11 | 0 | 0 | 0 | High-Tech Detective |
| 12 | 0 | 0 | 0 | Acrobat Brawler |
| 13 | 0 | 1 | 1 | Armored Billionaire |
| 14 | 0 | 1 | 1 | Cybernetic Spy |
| 15 | 0 | 1 | 1 | Ex-Military Pilot |
| 16 | 0 | 1 | 1 | Street Thief |
| 17 | 0 | 1 | 0 | Bounty Hunter |
| 18 | 0 | 1 | 0 | Ninja Assassin |
| 19 | 0 | 1 | 0 | Boxer Vigilante |
| 20 | 0 | 1 | 0 | Masked Detective |
The full CSV dataset is available in data/hero_ledger.csv.
When we ignore the hidden confounder
- Suited group (
$X=1$ ): 10 heroes, 6 victories, 4 defeats - Organic group (
$X=0$ ): 10 heroes, 7 victories, 3 defeats
A purely observational model would conclude that suits reduce victory probability by 10 percentage points. This is a misleading conclusion because it ignores confounding.
The causal assumptions are encoded in a Directed Acyclic Graph (DAG):
graph TD
Z[Power Class: Z] --> X[Training Mode: X]
Z --> Y[Battle Outcome: Y]
X --> Y[Battle Outcome: Y]
- Causal path:
$X \rightarrow Y$ . - Backdoor path:
$X \leftarrow Z \rightarrow Y$ .
Because
-
$P(X=1 \mid Z=1) = \frac{2}{8} = 0.25$ (Metahumans rarely use suits) -
$P(X=1 \mid Z=0) = \frac{8}{12} \approx 0.667$ (Street-level heroes rely on suits) -
$P(Y=1 \mid X=0, Z=1) = \frac{6}{6} = 1.00$ (Metahumans almost always win organically) -
$P(Y=1 \mid X=0, Z=0) = \frac{1}{4} = 0.25$ (Street-level heroes struggle organically)
Because
We now replace the observation operator with Pearl's intervention operator
The Backdoor Adjustment Formula is:
This formula computes the expected outcome under an intervention that forces
$P(Y=1 \mid X=1, Z=1) = \frac{2}{2} = 1.00$ $P(Y=1 \mid X=1, Z=0) = \frac{4}{8} = 0.50$ $P(Y=1 \mid X=0, Z=1) = \frac{6}{6} = 1.00$ $P(Y=1 \mid X=0, Z=0) = \frac{1}{4} = 0.25$
The calculations above are verified through hand-written mathematical workings. Below are scanned images of the manual derivations, demonstrating the step-by-step causal reasoning process.
This step isolates and counts the observational contingencies, revealing Simpson's Paradox in the raw data.
These calculations decompose the population by power class ($Z$) and compute conditional success rates for each subgroup. This is where confounding is quantified.
This final sheet applies Pearl's Backdoor Adjustment Formula, computing $P(Y=1 \mid do(X=1))$ and $P(Y=1 \mid do(X=0))$ by hand, yielding the true causal effects.
- Observational association:
$P(Y=1 \mid X=1) = 60%$ and$P(Y=1 \mid X=0) = 70%$ . - Interventional ground truth:
$P(Y=1 \mid do(X=1)) = 70%$ and$P(Y=1 \mid do(X=0)) = 55%$ .
The observational data presented an illusion: suits appeared harmful, but the causal analysis shows that forcing suit adoption increases victory probability by 15 percentage points. This is a textbook manifestation of Simpson's paradox caused by a hidden confounder.
| Analytical Framework | Notation | Value | Interpretation |
|---|---|---|---|
| Observational (Biased) | Apparent suit performance | ||
| Observational (Biased) | Apparent organic performance | ||
| Interventional (Causal) | True effect of forcing suits | ||
| Interventional (Causal) | True effect of organic training |
A clean Python verifier is included in scripts/verifier.py. It loads the same dataset, computes the observational fractions, and evaluates the backdoor adjustment.
python scripts/verifier.pySuppose we introduce a downstream variable
No.
├── README.md
├── LICENSE
├── .gitignore
├── data/
│ └── hero_ledger.csv
├── scripts/
│ └── verifier.py
└── solution-by-hand/
├── step1.jpg
├── step2.jpg
├── step2.1.jpg
└── step3.jpg
- Judea Pearl, Causality: Models, Reasoning, and Inference (2009)
- Judea Pearl, The Book of Why (2018)
- Andrej Karpathy, blog and teaching on foundational machine learning principles
- AI-by-hand style teaching and explanatory reasoning for causal models
This artifact is designed to be portfolio-ready. It combines:
- A compact, interpretable dataset
- A transparent DAG and backdoor analysis
- Full hand calculations
- A reproducible verification script
- A polished narrative that bridges research and engineering



