Day 47. Factorisation & the Markov Property
A DAG is also a statement about probability. Each variable depends only on its parents, so the joint distribution factorises into small pieces and implies conditional independences we can test.
- ●Write the Markov factorisation of a joint distribution for any DAG.
- ●Count the parameters saved by the factorisation.
- ●Compute joint, marginal and conditional probabilities from conditional probability tables.
- ●State and prove the local Markov property and use it to list testable independences.
Theory
From the chain rule to the DAG
For any ordering of variables, the chain rule of probability gives
A DAG says more: in a topological order, each variable depends on its predecessors only through its parents. The joint distribution then factorises:
A distribution that factorises this way is Markov with respect to the DAG. Each factor is a conditional probability table (CPT) for discrete variables, or a regression model for continuous ones.
Fewer parameters
With binary variables, an unrestricted joint distribution needs numbers. Under the factorisation, node needs one probability for each configuration of its parents, , so the total is
With 20 variables and at most two parents each: at most 80 numbers instead of about a million.
The local Markov property
Factorisation is equivalent to the local Markov property:
where are the non-descendants of . "Once you know a variable's direct causes, its other non-effects tell you nothing more about it."
Three building blocks
| Structure | Factorisation | Implied independence |
|---|---|---|
| Chain | ||
| Fork | ||
| Collider | (but not given ) |
Day 48 studies these in depth.
Faithfulness
The Markov property says which independences must hold. A distribution may have extra independences, for instance when two causal channels cancel exactly. Faithfulness assumes it does not: every independence in the data comes from the graph. Causal discovery (Day 98) relies on it.
Testable implications
Each implied independence is a testable implication of the DAG. If data reject , the graph is wrong. If data agree, the graph survives, but other graphs may imply the same independences.
Part 1 · Warm-up
For Exercises 3–4 use the chain with binary variables, , , , , .
Exercise 1 · Writing the factorisation
Write the factorisation for the DAG , , , , .
Show solution
Step 1. Parents: ; ; ; ; .
Step 2. One factor per node, conditioning on its parents:
Exercise 2 · Counting parameters
All five variables in Exercise 1 are binary. How many parameters does the factorisation need, compared with an unrestricted joint distribution?
Show solution
Step 1. Unrestricted: .
Step 2. Factorised: .
Answer: 11 versus 31.
Exercise 3 · A joint probability
Compute and .
Show solution
Step 1. Factorisation: .
Step 2. .
Step 3. .
Exercise 4 · Marginals by summing out
Compute and .
Show solution
Step 1. Sum over : .
Step 2. Sum over : .
Step 3. .
Exercise 5 · Local Markov statements
For the DAG in Exercise 1, write the local Markov independence for and for .
Show solution
Step 1. : parents ; descendants ; so the non-descendants other than parents are .
Step 2. .
Step 3. : parent ; non-descendants other than the parent are .
Step 4. .
Part 2 · Proofs
Exercise 6 · The chain screens off
For , prove from the factorisation.
Show solution
Step 1. By definition .
Step 2. Numerator: .
Step 3. Denominator: sum the numerator over : .
Step 4. The ratio is , which does not involve .
Exercise 7 · The fork screens off
For , prove .
Show solution
Step 1. Factorisation: .
Step 2. Divide by : .
Step 3. That is the definition of conditional independence.
Exercise 8 · The collider separates its causes
For , prove marginally.
Show solution
Step 1. Factorisation: .
Step 2. Sum over : .
Step 3. So and are independent. (Conditioning on generally destroys this; see Exercise 14.)
Exercise 9 · The factorisation is a valid distribution
Prove that sums to 1 over all values, for any choice of CPTs.
Show solution
Step 1. Order the nodes topologically, . The last node is a parent of no one, so it appears only in its own factor.
Step 2. Summing over first: , which removes the last factor.
Step 3. What remains is the same product for , in which is now last.
Step 4. Repeat until no factors remain: the total is 1.
Exercise 10 · Local Markov implies factorisation
Prove that if each satisfies the local Markov property, then the joint distribution factorises over the DAG.
Show solution
Step 1. Take a topological order and apply the chain rule: .
Step 2. The predecessors contain all parents of and no descendants of (descendants come later in the order).
Step 3. So the predecessors are plus some other non-descendants.
Step 4. By local Markov, those other non-descendants can be dropped: .
Step 5. Substituting gives the factorisation.
Part 3 · Applied
Exercise 11 · Vaccination and age
In a flu season, being older (, 30% of the population) affects both vaccination and infection , and vaccination affects infection: , , . , . Infection risks : young unvaccinated 0.10, young vaccinated 0.04, old unvaccinated 0.30, old vaccinated 0.12. Compute , and . Compare the crude risk ratio with the age-specific ones.
Show solution
Step 1. Joint probabilities with , using :
- young, vaccinated: ;
- young, unvaccinated: ;
- old, vaccinated: ;
- old, unvaccinated: .
Step 2. .
Step 3. , so .
Step 4. .
Step 5. Crude risk ratio: . Age-specific: and .
Answer: the vaccine cuts risk by 60% in each age group, but the crude comparison suggests only 38%, because the vaccinated are disproportionately old (the fork ).
Exercise 12 · A credit-scoring model
A bank models 10 binary borrower characteristics with a DAG in which each node has at most two parents. Give an upper bound on the number of parameters and compare with the unrestricted joint distribution. What is gained, and what is risked?
Show solution
Step 1. Each node needs at most parameters, so at most .
Step 2. Unrestricted: .
Step 3. Gain: each CPT is estimated from many borrowers, so estimates are precise even for rare combinations.
Answer: at most 40 versus 1,023. The risk is that the missing arrows are wrong; the DAG's implied independences should then be tested.
Exercise 13 · Testing a chain with survey data
A survey of 1,000 jobseekers records programme participation , whether skills improved and employment . Counts:
| 1 | 1 | 210 | 90 |
| 1 | 0 | 80 | 120 |
| 0 | 1 | 105 | 45 |
| 0 | 0 | 140 | 210 |
Do the data agree with the chain (no direct effect of the programme on employment)?
Show solution
Step 1. The chain implies .
Step 2. With improved skills: and .
Step 3. Without: and .
Step 4. Marginally: versus .
Answer: consistent with the chain: the programme is associated with employment, but only through skills. (With sampling noise, a formal test such as a stratified chi-square would be used.)
Exercise 14 · Hospital admissions (Berkson)
Flu (10% of people) and injury (5%) are independent. Hospital admission depends on both: is 0.01 for neither, 0.3 for flu only, 0.5 for injury only and 0.8 for both. Among admitted patients, compute , and .
Show solution
Step 1. Joint probabilities with :
- neither: ;
- flu only: ;
- injury only: ;
- both: .
Step 2. .
Step 3. .
Step 4. .
Step 5. .
Answer: in the population flu and injury are independent, but among hospital patients those with flu are far less likely to be injured. Conditioning on the collider creates the association.
Exercise 15 · Microfinance testable implications
A DAG for micro-entrepreneurs: education loan , income , business start , , rainfall . List the local Markov independences, and say which one you would test first with survey data.
Show solution
Step 1. : no parents; non-descendants other than itself: . So .
Step 2. : no parents; non-descendants: . So .
Step 3. : parent ; non-descendants other than : . So .
Step 4. : parent ; non-descendants: . So .
Step 5. : parents ; non-descendant . So .
Answer: test first: it says loans raise income only by starting businesses. Loans used for consumption smoothing or to pay off costlier debt would violate it.
Verify in Python
import itertools
import numpy as np
# Exercises 3-4: chain Z -> X -> Y
pZ = {1: .4, 0: .6}; pX1 = {1: .7, 0: .2}; pY1 = {1: .6, 0: .1}
P = {(z, x, y): pZ[z] * (pX1[z] if x else 1 - pX1[z]) * (pY1[x] if y else 1 - pY1[x])
for z, x, y in itertools.product([0, 1], repeat=3)}
print("sums to", round(sum(P.values()), 10), " P(1,1,1) =", round(P[1, 1, 1], 3), " P(0,1,0) =", round(P[0, 1, 0], 3))
print("P(X=1) =", round(sum(v for k, v in P.items() if k[1]), 3), " P(Y=1) =", round(sum(v for k, v in P.items() if k[2]), 3))
for x in (0, 1): # Y independent of Z given X
print(f"P(Y=1|X={x},Z=z):", [round(P[z, x, 1] / (P[z, x, 0] + P[z, x, 1]), 3) for z in (0, 1)])
# Exercise 11: vaccination and age
pO = {1: .3, 0: .7}; pV1 = {1: .8, 0: .4}; pI1 = {(0, 0): .10, (1, 0): .04, (0, 1): .30, (1, 1): .12} # key (v, o)
J = {(o, v): pO[o] * (pV1[o] if v else 1 - pV1[o]) * pI1[v, o] for o in (0, 1) for v in (0, 1)}
pV = {v: sum(pO[o] * (pV1[o] if v else 1 - pV1[o]) for o in (0, 1)) for v in (0, 1)}
r1 = (J[0, 1] + J[1, 1]) / pV[1]; r0 = (J[0, 0] + J[1, 0]) / pV[0]
print("P(I=1) =", round(sum(J.values()), 4), " P(I|V=1) =", round(r1, 4), " P(I|V=0) =", round(r0, 4), " crude RR =", round(r1 / r0, 3))
# Exercise 13: survey counts (P, S) -> (E=1, E=0)
c = {(1, 1): (210, 90), (1, 0): (80, 120), (0, 1): (105, 45), (0, 0): (140, 210)}
for (p, s), (a, b) in c.items():
print(f"P(E=1 | P={p}, S={s}) = {a / (a + b):.2f}")
# Exercise 14: Berkson's bias
pF, pJ = .1, .05; pH = {(0, 0): .01, (1, 0): .3, (0, 1): .5, (1, 1): .8}
H = {(f, j): (pF if f else 1 - pF) * (pJ if j else 1 - pJ) * pH[f, j] for f in (0, 1) for j in (0, 1)}
tot = sum(H.values())
print("P(H=1) =", round(tot, 5), " P(J|H) =", round((H[0, 1] + H[1, 1]) / tot, 3),
" P(J|H,F=1) =", round(H[1, 1] / (H[1, 0] + H[1, 1]), 3), " P(J|H,F=0) =", round(H[0, 1] / (H[0, 0] + H[0, 1]), 3))
Key takeaways
- A DAG factorises the joint distribution into one conditional distribution per node given its parents.
- This is equivalent to the local Markov property: each variable is independent of its non-descendants given its parents.
- Every implied independence is a testable implication; colliders are the exception that creates dependence when conditioned on.
Simulation Lab: Factorisation & Independence
Open full screen →Chains, forks and colliders on binary variables: the joint table from the factorisation and the independences it implies.
| z | x | y | P(z, x, y) |
|---|---|---|---|
| 1 | 0 | 0 | 0.108 |
| 1 | 0 | 1 | 0.012 |
| 1 | 1 | 0 | 0.112 |
| 1 | 1 | 1 | 0.168 |
| 0 | 0 | 0 | 0.432 |
| 0 | 0 | 1 | 0.048 |
| 0 | 1 | 0 | 0.048 |
| 0 | 1 | 1 | 0.072 |
Three binary variables with X in the middle. The joint table is built from the factorisation. Compare how Z predicts Y overall and within each value of X: chains and forks make the within-X differences zero; a collider makes the overall difference zero instead. (In the collider, Y is a fair coin and the sliders set how Z and Y raise X.)