Independence and conditional independence
独立性与条件独立
Check whether joint probabilities factorize, see how conditioning changes dependence, and distinguish independence from zero covariance.
independenceLearning one answer may change the other
Imagine two binary test flags . Assign equal probability to the four pairs . Knowing the first flag leaves the second equally likely to be 0 or 1. The flags are independent in this model.
Now a dashboard reveals only , which is 1 when the flags differ. Given , observing tells you exactly: they must agree. Independence before seeing the dashboard does not imply independence after conditioning on its message.
| , flags differ | Joint probability | ||
|---|---|---|---|
| 0 | 0 | 0 | 1/4 |
| 0 | 1 | 1 | 1/4 |
| 1 | 0 | 1 | 1/4 |
| 1 | 1 | 0 | 1/4 |
The whole joint distribution must factorize
For discrete variables, independence requires the following equality for every value pair, including pairs whose joint probability is zero:
When , dividing both sides gives . Checking just one pair is insufficient. More generally, independence is a condition on all events associated with the variables; the discrete formula is a convenient finite-table version. Deep Learning, Section 3.7
Conditional independence given discrete requires factorization within every stratum having positive probability:
The positive-probability qualifier prevents division by zero. Conditional distributions for continuous conditioning variables need a more general definition and hold up to probability-zero exceptions; ordinary event-ratio formulas do not directly condition on a singleton with probability zero. MML, Section 6.4.5
In the dashboard example, all three pairs , , and are independent. Yet the triple is not mutually independent: , whereas the product of the three marginal probabilities is . Pairwise independence does not guarantee that every group factorizes.
For finite second moments, independence implies , hence zero covariance. The converse fails. Let be uniform on and . Symmetry gives , so covariance is zero. But , whereas . Knowing reveals its magnitude completely.
Check missing cells as well as observed ones
This complete program works with small, valid, normalized tables of exact probabilities. Missing value pairs count as zero joint mass. It tests both the dashboard model and the zero-covariance counterexample.
from fractions import Fraction as F
from itertools import product
def pair_independent(table, i, j):
if not table or any(p < 0 for p in table.values()) or sum(table.values()) != 1:
raise ValueError("normalized nonnegative table required")
px, py, joint = {}, {}, {}
for row, p in table.items():
x, y = row[i], row[j]
px[x] = px.get(x, F(0)) + p
py[y] = py.get(y, F(0)) + p
joint[x,y] = joint.get((x,y), F(0)) + p
return all(joint.get((x,y), F(0)) == px[x]*py[y] for x in px for y in py)
def condition(table, axis, value):
selected = {row:p for row,p in table.items() if row[axis] == value}
mass = sum(selected.values())
if mass <= 0:
raise ValueError("conditioning event has zero probability")
return {row:p/mass for row,p in selected.items()}
flags = {(x,y,x^y): F(1,4) for x,y in product([0,1], repeat=2)}
assert all(pair_independent(flags,i,j) for i,j in [(0,1),(0,2),(1,2)])
assert flags[0,0,0] != F(1,2)**3
assert not pair_independent(condition(flags,2,0),0,1)
nonlinear = {(x,abs(x)): F(1,4) for x in [-2,-1,1,2]}
ex = sum(x*p for (x,y),p in nonlinear.items())
ey = sum(y*p for (x,y),p in nonlinear.items())
exy = sum(x*y*p for (x,y),p in nonlinear.items())
assert exy-ex*ey == 0
assert not pair_independent(nonlinear,0,1)
common = {(0,0,0): F(1,2), (1,1,1): F(1,2)}
assert not pair_independent(common,0,1)
assert all(pair_independent(condition(common,2,z),0,1) for z in [0,1])
For listed outcomes and marginal support sizes , pair checking costs expected dictionary operations with storage. Verifying mutual independence across many variables can require a much larger product space. This exact calculation concerns the supplied model; it does not prove independence in the population from a finite empirical table.
What independence does not establish
Identically distributed observations need not be independent. Copying one random value a thousand times preserves its marginal distribution but adds no independent observations. Conversely, two independent measurements can have different distributions. The phrase “independent and identically distributed,” abbreviated i.i.d., contains two separate assumptions.
Conditioning can also remove dependence. If for a fair binary , and are dependent marginally. Given , both are constants and their conditional distribution factorizes. Together with the dashboard example, this shows why neither conditional nor marginal independence generally implies the other.
Statistical independence is not by itself a causal conclusion. Sampling, omitted variables, selection rules, or special parameter choices can affect observed dependencies. A statistical test that fails to reject independence is not a proof of exact independence; finite sample size and test sensitivity matter.
Find a cell that settles the question
- Given in the dashboard example, what is ? Answer: 0, while the product of conditional marginals is . They are not conditionally independent.
- Does zero correlation prove independence for arbitrary variables? Answer: no; and above have nonzero variances and zero correlation but are dependent.
- Are mutually exclusive events with positive probabilities independent? Answer: no. Their intersection has probability zero while the product is positive.
- Why check missing cells? Answer: a missing pair may have zero joint mass but positive marginal-product mass, immediately disproving factorization.
Assumptions determine what can be simplified
Naive Bayes uses conditional independence to factor a likelihood; probabilistic graphical models record related factorization assumptions. Evaluation procedures often assume independence between sampled units. Repeated records from the same person or device can violate that assumption even when rows are shuffled. Identify the unit of observation and the conditioning information before simplifying a probability expression.
Make a prediction, then check
Three binary variables are pairwise independent. Must every triple probability equal the product of three marginals?
Learning objectives
- Test independence using the full joint table, including zero-probability pairs.
- Give counterexamples for pairwise versus mutual independence, conditioning effects, and uncorrelated dependence.
Prerequisites & connections
Explore related knowledge →References
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020 - Deep Learning — Chapter 3: Probability and Information Theory
Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: cited-source comparison, re-derivation and recalculation, bilingual argument comparison, and executed Python assertions; no independent human peer review.
- Checked every XOR-table cell: pairwise independence, triple probability 1/4 versus 1/8, dependence given Z=0, and conditionally independent constants given a common cause.
- Recomputed zero covariance for X and |X|; ran missing-cell and independent-product checks. Corrected the English test statement to match the Chinese distinction between failing to reject independence and proving it.
- Compared arguments, modeling assumptions, numbers, and exercise answers across languages; structural checks separately compare display formulas, code, references, and main sections. No independent human peer review.
Source locations checked:
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft) · §6.4.5; PDF pp. 200–201: independence and conditional independence
- Deep Learning — Chapter 3: Probability and Information Theory · §3.7–3.8: factorization and covariance
Related topics