Search

Search papers and lessons

Exchangeability

Level 3 · 12 min read

Exchangeable variables have the same joint probabilities in any order. They need not be independent, yet they justify treating data as draws from one shared, unknown source.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Calculus
  • Sign in to see your progress

TL;DR

A sequence of random variables is exchangeable when its joint probabilities do not change if you reorder the positions. Any rearrangement of an outcome is as likely as the outcome itself. Exchangeable variables do not have to be independent, but they are almost as easy to reason about, and the common case of independent draws from one unknown source always qualifies.

Where you'll see it: in the assumption that the rows of a dataset can be shuffled, in permutation tests, and in Bayesian models, where an unknown parameter links the observations without singling out any position.

Intuition

Does the order matter?

Write the outcome of three draws as a string, such as RBR (red, blue, red). Now ask a simple question. Is RBR just as likely as BRR and RRB? If you shuffle the letters, does the chance of the pattern stay the same? If it does for every pattern, the sequence is exchangeable.

That is a question about positions, not about the values. Exchangeability means the positions carry no information of their own. Draw number 1 is not special, and neither is draw number 3. Only the contents of the pattern matter.

Why this idea exists

In many problems we have no reason to tell the positions apart. We have not labelled the patients, the coin tosses, or the survey respondents by anything that matters. The usual model says the draws are independent and identically distributed (iid). That is a strong claim: it says the draws do not influence each other at all. Real samples often do influence each other a little, for example when they come from one batch, one urn or one population of unknown mix. Exchangeability keeps the one thing we are confident about, that the order carries no information, and drops the claim of no influence.

flowchart LR
  A[Independent and identically distributed] --> B[Exchangeable]
  C[Mixture of iid draws from an unknown source] --> B
  B --> D[Order carries no information]
  B -.->|not the other way round| E[Independence]

The arrows show the logic. Every iid sequence is exchangeable. The second route is the important one: exchangeable sequences look like mixtures of iid draws, so exchangeability is the right assumption whenever a hidden shared cause is plausible.

The math

Definition

Definition: Exchangeable sequence

Random variables X1,…,XnX_1, \dots, X_n are exchangeable if, for every permutation π\pi of the positions {1,…,n}\{1, \dots, n\}, the vector (Xπ(1),…,Xπ(n))(X_{\pi(1)}, \dots, X_{\pi(n)}) has the same joint distribution as (X1,…,Xn)(X_1, \dots, X_n). For discrete variables this means

P(X1=x1,…,Xn=xn)=P(X1=xπ(1),…,Xn=xπ(n))P(X_1 = x_1, \dots, X_n = x_n) = P(X_1 = x_{\pi(1)}, \dots, X_n = x_{\pi(n)})

for every choice of values x1,…,xnx_1, \dots, x_n.

Here π\pi is a permutation, a rearrangement of the positions 11 to nn. The right-hand side is the probability of the rearranged pattern. The definition says that rearranging a pattern never changes its probability. A sequence of length nn has to pass this test for every nn we care about.

Exchangeability is a property of the joint distribution, not of any single variable. Each XiX_i on its own may have the same distribution as the others (an identically distributed sequence is one where every XiX_i has the same marginal law), but exchangeability asks more: the way the variables move together must also be unchanged by reordering.

Iid implies exchangeable

Suppose the variables are independent and identically distributed with probability mass function pp (the function giving the probability of each value). Independence turns the joint probability into a product, so

  1. P(X1=x1,…,Xn=xn)=p(x1) p(x2)⋯p(xn)P(X_1 = x_1, \dots, X_n = x_n) = p(x_1)\, p(x_2) \cdots p(x_n).
  2. A product of numbers does not change when its factors are reordered: p(xπ(1))⋯p(xπ(n))=p(x1)⋯p(xn)p(x_{\pi(1)}) \cdots p(x_{\pi(n)}) = p(x_1) \cdots p(x_n).
  3. The right-hand side of step 2 is exactly the joint probability of the rearranged pattern, so the definition holds.

The converse fails. The next example gives an exchangeable sequence that is not independent.

Exchangeable is not the same as independent

Exchangeable sequences can be strongly dependent. The two statements differ in what they test. Independence asks whether knowing one variable changes the probability of another. Exchangeability asks whether reordering changes the joint probabilities. A sequence can pass the second test while failing the first, as Example 1 shows.

de Finetti's representation

The central fact about exchangeable sequences is due to de Finetti. For an infinite exchangeable sequence there is a hidden random parameter θ\theta such that, given θ\theta, the variables are iid. The joint probability is an average over θ\theta:

P(X1=x1,…,Xn=xn)=∫(∏i=1np(xi∣θ)) ρ(θ) dθP(X_1 = x_1, \dots, X_n = x_n) = \int \Big( \prod_{i=1}^{n} p(x_i \mid \theta) \Big)\, \rho(\theta)\, d\theta

Here p(x∣θ)p(x \mid \theta) is a conditional probability: the probability of one value when the parameter is θ\theta, and ρ(θ)\rho(\theta) is the probability density of the parameter itself (its prior, in Bayesian language). For a discrete parameter, replace the integral by a sum. In words: an exchangeable sequence is what you get when you draw a hidden setting once, then draw iid values from that setting. Because the variables are iid given θ\theta, the law of large numbers says the long-run fraction of each outcome settles at its probability under θ\theta. This is the reason exchangeability is so useful. It takes a general symmetry and turns it into the familiar iid model with an unknown parameter.

Worked examples

Example
Example 1: a tiny urn (exchangeable, not independent)

Start with one red ball (R) and one blue ball (B) in an urn. Draw a ball, note its colour, put it back, and add one more ball of the same colour. Call the first draw X1X_1 and the second X2X_2 (a draw is one Bernoulli-style yes/no outcome: red or not). This is a Pólya urn.

  1. P(X1=R)=12P(X_1 = R) = \tfrac{1}{2}. The urn now holds 2 red and 1 blue, so 3 balls in total.
  2. P(X2=B∣X1=R)=13P(X_2 = B \mid X_1 = R) = \tfrac{1}{3}. So P(R,B)=12×13=16P(R, B) = \tfrac{1}{2} \times \tfrac{1}{3} = \tfrac{1}{6}.
  3. P(X1=B)=12P(X_1 = B) = \tfrac{1}{2}. The urn now holds 1 red and 2 blue.
  4. P(X2=R∣X1=B)=13P(X_2 = R \mid X_1 = B) = \tfrac{1}{3}. So P(B,R)=12×13=16P(B, R) = \tfrac{1}{2} \times \tfrac{1}{3} = \tfrac{1}{6}.
  5. The two orders are equally likely, P(R,B)=P(B,R)=16P(R, B) = P(B, R) = \tfrac{1}{6}. That is exchangeability for n=2n = 2.
  6. Check independence. P(R,R)=12×23=13P(R, R) = \tfrac{1}{2} \times \tfrac{2}{3} = \tfrac{1}{3}. The marginal is P(X2=R)=13+16=12P(X_2 = R) = \tfrac{1}{3} + \tfrac{1}{6} = \tfrac{1}{2}. If the draws were independent, P(R,R)P(R, R) would be 12×12=14\tfrac{1}{2} \times \tfrac{1}{2} = \tfrac{1}{4}, not 13\tfrac{1}{3}.

Interpretation: the first draw changes what the second is likely to be, since a red first draw makes red more likely again. But this influence does not depend on which position the draw occupies, so the sequence is exchangeable without being independent.

Example
Example 2: a mixture of two coins (the textbook case)

Choose one of two coins with equal chance. Coin A lands heads with probability 0.2, and coin B with probability 0.8. Flip the chosen coin twice, giving X1X_1 and X2X_2. Both flips use the same coin, so they are linked, but no position is special.

  1. Given coin A, the flips are independent, so P(H,H∣A)=0.2×0.2=0.04P(H, H \mid A) = 0.2 \times 0.2 = 0.04.
  2. Given coin B, P(H,H∣B)=0.8×0.8=0.64P(H, H \mid B) = 0.8 \times 0.8 = 0.64.
  3. Average over the coin choice: P(H,H)=12×0.04+12×0.64=0.34P(H, H) = \tfrac{1}{2} \times 0.04 + \tfrac{1}{2} \times 0.64 = 0.34.
  4. For a head then a tail, given A the probability is 0.2×0.8=0.160.2 \times 0.8 = 0.16, and given B it is 0.8×0.2=0.160.8 \times 0.2 = 0.16. So P(H,T)=12×0.16+12×0.16=0.16P(H, T) = \tfrac{1}{2} \times 0.16 + \tfrac{1}{2} \times 0.16 = 0.16.
  5. By the same steps, P(T,H)=0.16P(T, H) = 0.16, so the two orders match.
  6. P(T,T)=12×0.64+12×0.04=0.34P(T, T) = \tfrac{1}{2} \times 0.64 + \tfrac{1}{2} \times 0.04 = 0.34. The four probabilities add to 0.34+0.16+0.16+0.34=10.34 + 0.16 + 0.16 + 0.34 = 1, as they must.
  7. The first flip is heads with probability 0.34+0.16=0.50.34 + 0.16 = 0.5. Independence would need P(H,H)=0.5×0.5=0.25P(H, H) = 0.5 \times 0.5 = 0.25, but the true value is 0.340.34.

Interpretation: once we know which coin we hold, the flips are iid, with 0.04=0.220.04 = 0.2^2 for coin A. We do not know the coin, so the flips move together. This is de Finetti's picture in a single example: exchangeable means iid given an unknown parameter, averaged over that parameter.

Example
Example 3: tickets drawn without replacement (realistic)

A box holds 100 tickets, and 30 of them win. Draw three tickets one after another, without putting any back. Let XiX_i record whether draw ii is a winner (W) or a loser (L).

  1. P(X1=W)=30100=0.30P(X_1 = W) = \tfrac{30}{100} = 0.30.
  2. P(W,W)=30100×2999=8709900≈0.0879P(W, W) = \tfrac{30}{100} \times \tfrac{29}{99} = \tfrac{870}{9900} \approx 0.0879.
  3. P(W,L)=30100×7099=21009900≈0.2121P(W, L) = \tfrac{30}{100} \times \tfrac{70}{99} = \tfrac{2100}{9900} \approx 0.2121.
  4. P(L,W)=70100×3099=21009900≈0.2121P(L, W) = \tfrac{70}{100} \times \tfrac{30}{99} = \tfrac{2100}{9900} \approx 0.2121. This matches step 3.
  5. P(L,L)=70100×6999=48309900≈0.4879P(L, L) = \tfrac{70}{100} \times \tfrac{69}{99} = \tfrac{4830}{9900} \approx 0.4879. The four probabilities add to 99009900=1\tfrac{9900}{9900} = 1.
  6. The second draw is a winner with probability 870+21009900=0.30\tfrac{870 + 2100}{9900} = 0.30, the same as the first. Reordering the draws does not change the picture.
  7. An iid model would give P(W,W)=0.30×0.30=0.09P(W, W) = 0.30 \times 0.30 = 0.09. The true value is 0.08790.0879, so the draws are not independent. Each winning ticket removed leaves one fewer winner.

Interpretation: the order of the draws never matters, but the draws affect each other. Because the box is large compared with the number of draws, the gap is small here. When the population is much larger than the sample, people routinely treat such draws as iid.

Tradeoffs and failure modes

Exchangeability is a weaker assumption than iid, so it is the safer one to make. It is still an assumption, and the data cannot prove it on their own. The table lists the common situations.

SituationWhat goes wrongBetter choice
The data have a natural order, such as a time series or a drift over timeEarly values carry information about later ones, so position mattersModel the order directly, with a time-series or Markov model
A small population is sampled without replacementThe draws are not iid, and the gap can be largeUse the exact model for drawing without replacement
Several hidden sources are mixed togetherTreating the whole sequence as one source hides the groupsAdd a group variable (a [[mixture-model
A [[permutation-testpermutation test]] is runThe test is valid only if shuffling leaves the null distribution unchanged

A common mistake is to assume exchangeability because the rows happen to be listed in a random-looking order. The order of a file tells you nothing about whether the variables are exchangeable. What matters is whether the process that generated the data treats the positions alike.

History

The idea was developed by the Italian mathematician Bruno de Finetti in the late 1920s and early 1930s, as part of his work on the foundations of probability and subjective belief. He was asking how someone can reason about a sequence of events they consider interchangeable, and his representation theorem answered it: such beliefs are mixtures of iid beliefs, averaged over an unknown parameter. The Pólya urn, used in Example 1, belongs to the same period of work on urn models that was developed by George Pólya.

The idea caught on because it gave a clean justification for Bayesian models. A model that places a prior over an unknown parameter and then assumes the data are iid given that parameter is exactly an exchangeable model. Exchangeability became the standard way to say why a dataset can be modelled as repeated draws from an unknown source, even when the draws are not truly independent.

Recap

A joint distribution gives the probability of a whole pattern. Reordering the positions of that pattern leaves the probability unchanged exactly when the sequence is exchangeable. Independent identically distributed sequences are a special case, and de Finetti showed that every exchangeable sequence is a mixture of such sequences. Two ideas build on this. A permutation test shuffles labels to ask whether an observed difference could be chance, which is valid only under exchangeability. Causal inference uses the same idea when it asks whether treated and untreated groups are comparable.

Check yourself

QuestionRecall: in your own words, what does it mean for a sequence of random variables to be exchangeable?Show answer

A sequence is exchangeable when reordering its positions does not change its joint probabilities. For any pattern of values, the pattern and every rearrangement of it are equally likely. The variables may still be dependent, but the position of each variable carries no information about it.

QuestionComputation: an urn holds 3 red and 1 blue ball. Draw one ball, note its colour, put it back and add one more of the same colour. Find P(X1=R,X2=B)P(X_1 = R, X_2 = B) and P(X1=B,X2=R)P(X_1 = B, X_2 = R). Are they equal?Show answer

P(X1=R)=34P(X_1 = R) = \tfrac{3}{4}, and after that draw the urn holds 4 red and 1 blue, so P(X2=B∣X1=R)=15P(X_2 = B \mid X_1 = R) = \tfrac{1}{5}. Therefore P(R,B)=34×15=320P(R, B) = \tfrac{3}{4} \times \tfrac{1}{5} = \tfrac{3}{20}. For the other order, P(X1=B)=14P(X_1 = B) = \tfrac{1}{4}, and the urn then holds 3 red and 2 blue, so P(X2=R∣X1=B)=35P(X_2 = R \mid X_1 = B) = \tfrac{3}{5}. Therefore P(B,R)=14×35=320P(B, R) = \tfrac{1}{4} \times \tfrac{3}{5} = \tfrac{3}{20}. They are equal, as exchangeability requires, even though the second draw clearly depends on the first.

QuestionWhy: why does sampling without replacement from a finite box give an exchangeable sequence but not an iid one?Show answer

Reordering the draws does not change the set of tickets that were drawn, so the probability of a pattern is the same for any order. This is the symmetry that exchangeability captures. Independence fails because each draw changes the box: removing a winning ticket leaves fewer winners for the next draw. Example 3 shows the gap, with P(W,W)≈0.0879P(W, W) \approx 0.0879 rather than the iid value 0.090.09.

QuestionApplied: a dataset's rows are shuffled before being split into training and test sets. Is it safe to assume the rows are exchangeable? What would make that assumption fail?Show answer

Shuffling is the kind of reordering exchangeability allows, so if the rows are exchangeable, shuffling changes nothing about their joint law and the split is fair. The assumption fails when the rows come from a process with a trend, such as readings from a sensor that drifts over time, or when several sources are stacked in blocks. A quick check is to compare the first and last parts of the data for systematic differences. If they differ, a time-aware or group-aware split is needed.

Sources

Exchangeability — explained simply | ungoon.me