AI Wiki中文/EN

Independence and conditional independence

独立性与条件独立

Check whether joint probabilities factorize, see how conditioning changes dependence, and distinguish independence from zero covariance.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Learning one answer may change the other

Imagine two binary test flags X,YX,Y. Assign equal probability to the four pairs (0,0),(0,1),(1,0),(1,1)(0,0),(0,1),(1,0),(1,1). 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 Z=XxorYZ=X\mathbin{\mathrm{xor}}Y, which is 1 when the flags differ. Given Z=0Z=0, observing XX tells you YY exactly: they must agree. Independence before seeing the dashboard does not imply independence after conditioning on its message.

XXYYZZ, flags differJoint probability
0001/4
0111/4
1011/4
1101/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:

P(X=x,Y=y)=P(X=x)P(Y=y).P(X=x,Y=y)=P(X=x)P(Y=y).

When P(Y=y)>0P(Y=y)>0, dividing both sides gives P(X=x∣Y=y)=P(X=x)P(X=x\mid Y=y)=P(X=x). 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 ZZ requires factorization within every stratum having positive probability:

P(X=x,Y=y∣Z=z)=P(X=x∣Z=z)P(Y=y∣Z=z),P(Z=z)>0.P(X=x,Y=y\mid Z=z)=P(X=x\mid Z=z)P(Y=y\mid Z=z),\qquad P(Z=z)>0.

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 (X,Y)(X,Y), (X,Z)(X,Z), and (Y,Z)(Y,Z) are independent. Yet the triple is not mutually independent: P(X=0,Y=0,Z=0)=1/4P(X=0,Y=0,Z=0)=1/4, whereas the product of the three marginal probabilities is 1/81/8. Pairwise independence does not guarantee that every group factorizes.

For finite second moments, independence implies E[XY]=E[X]E[Y]E[XY]=E[X]E[Y], hence zero covariance. The converse fails. Let XX be uniform on {−2,−1,1,2}\{-2,-1,1,2\} and Y=∣X∣Y=|X|. Symmetry gives E[X]=E[XY]=0E[X]=E[XY]=0, so covariance is zero. But P(Y=2∣X=2)=1P(Y=2\mid X=2)=1, whereas P(Y=2)=1/2P(Y=2)=1/2. Knowing XX 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 nn listed outcomes and marginal support sizes a,ba,b, pair checking costs expected O(n+ab)O(n+ab) dictionary operations with O(n+a+b)O(n+a+b) 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 X=Y=ZX=Y=Z for a fair binary ZZ, XX and YY are dependent marginally. Given ZZ, 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

  1. Given Z=0Z=0 in the dashboard example, what is P(X=0,Y=1∣Z=0)P(X=0,Y=1\mid Z=0)? Answer: 0, while the product of conditional marginals is 1/41/4. They are not conditionally independent.
  2. Does zero correlation prove independence for arbitrary variables? Answer: no; XX and ∣X∣|X| above have nonzero variances and zero correlation but are dependent.
  3. Are mutually exclusive events with positive probabilities independent? Answer: no. Their intersection has probability zero while the product is positive.
  4. 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?

Choose one answer

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

  1. Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
    Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020
  2. 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:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.