Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 23: Independence and d-Separation — Implementation

Open in Colab
  1. A small Bayesian-network class: ancestral sampling and exact queries

  2. Testing independence in data, and comparing with d-separation

  3. Berkson’s paradox: conditioning on a collider creates a correlation

  4. Simpson’s paradox: a common cause reverses a trend, and adjusting for it

  5. Every independence a graph implies: the local Markov property

P(D = 1): exact 0.4360, from 100 000 samples 0.4354

2. Testing Independence in Data

With data instead of tables, independence must be tested. For X⊥Y∣ZX \perp Y \mid Z: split the data by every value of ZZ, run a chi-squared test of independence on the X×YX \times Y table of each part, and add the statistics and degrees of freedom. A small p-value means the data contradict independence.

query                  d-separated   p-value
S ⫫ E | {}                   False         0
S ⫫ E | {L}                   True    0.0491
T ⫫ L | {}                    True     0.893
T ⫫ L | {E}                  False         0
A ⫫ D | {}                   False     0.391
A ⫫ D | {E}                  False     0.933
A ⫫ S | {}                    True     0.278

Where the graph says dependent and the dependence is strong (S and E; T and L given E), the p-values are 0. Two rows deserve a closer look. S⊥E∣LS \perp E \mid L is a true independence, yet its p-value is 0.049: at the 5% level, a true independence is rejected one time in twenty, and this is such a time. AA and DD are dependent according to the graph, yet the test finds nothing (0.39, and 0.93 given E): visits to Asia are rare (1%) and their effect on dyspnoea passes through two uncertain links, so the dependence is real but far too weak to see in 100 000 patients. Tests can only fail to find a dependence; that is why structure learning from data (Chapter 25) is hard.

3. Berkson’s Paradox

A collider observed by selection: a scholarship goes to students who are either very talented or very hard-working. In the whole population, talent and effort are independent. Among scholarship holders they are negatively correlated, because a holder who lacks one must have the other.

correlation in the population: +0.033
correlation among the 1444 selected: -0.679

Talent and effort are unrelated in the population (correlation +0.03); among the 1 444 selected students the correlation is −0.68. Hospital studies, published papers (selected for striking results) and dating apps all select on colliders in this way.

4. Simpson’s Paradox

A fork confounds. In a classic study of kidney-stone treatments (Charig et al., 1986), treatment A was given more often for large stones, which are harder to treat. The numbers below are the study’s.

small  stones:  A 93.1%   B 86.7%
large  stones:  A 73.0%   B 68.8%
overall:        A 78.0%   B 82.6%

Treatment A succeeds more often for small stones (93.1% against 86.7%) and for large stones (73.0% against 68.8%), yet less often overall (78.0% against 82.6%). A was mostly given for large stones, the hard cases.

Stone size is a common cause of the treatment choice and of the outcome: a fork, open as long as size is not taken into account. To estimate what giving A or B to everyone would do, P(success∣do(t))P(\text{success} \mid do(t)), we adjust for the confounder (the back-door adjustment):

P(success∣do(t))=∑sP(success∣t,s) P(s)P(\text{success} \mid do(t)) = \sum_{s} P(\text{success} \mid t, s)\, P(s)
P(success | do(A)) = 83.3%
P(success | do(B)) = 77.9%

Adjusted for stone size, A is the better treatment: 83.3% against 77.9%, the direction found within each group.

Adjusting is right for a fork (a confounder), and wrong for a collider: adjusting for a common effect, as in Berkson’s example, creates a bias that was not there. The graph, not the data, tells you which variables to adjust for.

5. Every Independence a Graph Implies

The local Markov property: each variable is independent of its non-descendants given its parents. These statements imply all the others (through d-separation). For the Asia network:

A ⫫ {B, L, S} | {}
S ⫫ {A, T} | {}
T ⫫ {B, L, S} | {A}
L ⫫ {A, B, T} | {S}
B ⫫ {A, E, L, T, X} | {S}
E ⫫ {A, B, S} | {T, L}
X ⫫ {A, B, D, L, S, T} | {E}
D ⫫ {A, L, S, T, X} | {E, B}

Summary

  • Ancestral sampling draws each variable after its parents; enough samples reproduce the exact probabilities.

  • A pooled chi-squared test checks conditional independence in data; its verdicts follow d-separation when the sample is large.

  • Selecting on a collider creates spurious correlations (Berkson); a confounding fork can reverse a trend (Simpson).

  • Adjust for confounders, never for colliders: the graph decides.

  • The local Markov property lists the basic independences from which all others follow.