Search

Search papers and lessons

Joint Distribution

Level 2 · 9 min read

A joint distribution gives the probability that several random variables take particular values together, and it contains everything about how they relate.

On this page

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

TL;DR

A joint distribution assigns a probability to every combination of values of two or more random variables. It tells you how likely XX and YY are to take particular values together. From it you can recover each variable on its own (the marginal) and how one variable behaves once you know the other (the conditional).

Without the joint, two variables are just two separate stories. With it, you can ask questions about how they move together.

Where you'll see it: in a pair of sensor readings that drift together, in the pixel values of an image treated as one vector, and in the (input, label) pairs of a supervised learning dataset.

Intuition

A table of who-with-what

Suppose you record the weather (XX: sunny or rainy) and whether a person carries an umbrella (YY: yes or no) every morning for a year. Count the mornings in each cell and divide by the total. The grid of four numbers is the joint distribution.

umbrella: yesumbrella: nototal
sunny0.100.500.60
rainy0.300.100.40
total0.400.601.00

The four inner cells are the joint. The bottom and right margins, the row and column totals, are the marginals. They are what you see if you look at one variable and ignore the other. The marginal totals are the shadows the joint casts on each axis.

The table already shows something a single variable cannot. Rainy mornings are much more likely to come with an umbrella: 0.300.30 out of 0.400.40, against 0.100.10 out of 0.600.60 on sunny days. That dependence lives in the joint, not in either margin.

00.20.40.60.8100.511.52ydensity
  • Y given X = 0
  • Y given X = 1
  • marginal of Y
For a continuous pair with density f(x, y) = x + y on the unit square, slicing at X = 0 and X = 1 gives two different shapes. The marginal of Y is the weighted mix of those slices.

The plot shows the continuous version of the same idea. Fix XX at one value and the joint becomes a curve in YY. Those curves are the conditionals. Averaging them over all values of XX gives back the marginal.

The math

Definitions

Definition: Joint distribution

For discrete random variables XX and YY, the joint probability mass function is

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

It is never negative, and its values sum to 1 over all pairs. For continuous variables, the joint probability density f(x,y)f(x, y) is never negative and integrates to 1 over the whole plane. The probability that (X,Y)(X, Y) lands in a region AA is ∬Af(x,y) dx dy\iint_A f(x, y)\, dx\, dy.

Here xx and yy are the values the two variables can take, and p(x,y)p(x, y) is the probability of seeing both at once. The same definition extends to any number of variables. Three variables give a joint p(x,y,z)p(x, y, z), and so on.

Marginal distributions

To get the distribution of one variable, add (discrete) or integrate (continuous) over the other:

pX(x)=∑yp(x,y),fX(x)=∫f(x,y) dy.p_X(x) = \sum_{y} p(x, y), \qquad f_X(x) = \int f(x, y)\, dy.

This is "integrating out" YY. Each value of xx collects all the ways it can happen, whatever yy turns out to be. In the umbrella table, pX(rainy)=0.30+0.10=0.40p_X(\text{rainy}) = 0.30 + 0.10 = 0.40.

Conditional distributions

The conditional distribution of YY given X=xX = x restricts attention to the slice where X=xX = x and renormalises it so it sums to 1:

pY∣X(y∣x)=p(x,y)pX(x),when pX(x)>0.p_{Y \mid X}(y \mid x) = \frac{p(x, y)}{p_X(x)}, \qquad \text{when } p_X(x) \gt 0.

Rearranged, this is the product rule: p(x,y)=pY∣X(y∣x) pX(x)p(x, y) = p_{Y \mid X}(y \mid x)\, p_X(x). Any joint can be built by taking one variable's marginal and then a conditional for the next. For three variables, p(x,y,z)=p(x) p(y∣x) p(z∣x,y)p(x, y, z) = p(x)\, p(y \mid x)\, p(z \mid x, y).

Independence

XX and YY are independent exactly when the joint factorises into its marginals:

p(x,y)=pX(x) pY(y)for every x and y.p(x, y) = p_X(x)\, p_Y(y) \quad \text{for every } x \text{ and } y.

Equivalently, the conditional equals the marginal: pY∣X(y∣x)=pY(y)p_{Y \mid X}(y \mid x) = p_Y(y). Learning XX tells you nothing about YY.

A continuous example

Take f(x,y)=x+yf(x, y) = x + y on the unit square [0,1]×[0,1][0, 1] \times [0, 1]. First check it is a density:

∫01∫01(x+y) dy dx=∫01(x+12)dx=12+12=1.\int_0^1 \int_0^1 (x + y)\, dy\, dx = \int_0^1 \left(x + \tfrac12\right) dx = \tfrac12 + \tfrac12 = 1.

The marginal of XX is fX(x)=∫01(x+y) dy=x+12f_X(x) = \int_0^1 (x + y)\, dy = x + \tfrac12 on [0,1][0, 1]. The conditional density of YY given X=xX = x is then f(y∣x)=x+yx+12f(y \mid x) = \dfrac{x + y}{x + \tfrac12}.

To find P(X≤12,Y≤12)P(X \le \tfrac12, Y \le \tfrac12), integrate the joint over the lower-left quarter. The inner integral is ∫01/2(x+y) dy=x2+18\int_0^{1/2}(x + y)\, dy = \tfrac{x}{2} + \tfrac18. The outer one is ∫01/2(x2+18)dx=116+116=18\int_0^{1/2}\left(\tfrac{x}{2} + \tfrac18\right) dx = \tfrac1{16} + \tfrac1{16} = \tfrac18.

Since (x+y)≠(x+12)(y+12)(x + y) \ne (x + \tfrac12)(y + \tfrac12) in general, XX and YY are not independent.

Worked examples

Example
The umbrella table, step by step

Use the table above: P(sunny,yes)=0.10P(\text{sunny}, \text{yes}) = 0.10, P(sunny,no)=0.50P(\text{sunny}, \text{no}) = 0.50, P(rainy,yes)=0.30P(\text{rainy}, \text{yes}) = 0.30, P(rainy,no)=0.10P(\text{rainy}, \text{no}) = 0.10.

  1. Marginals: P(yes)=0.10+0.30=0.40P(\text{yes}) = 0.10 + 0.30 = 0.40, and P(rainy)=0.30+0.10=0.40P(\text{rainy}) = 0.30 + 0.10 = 0.40.
  2. Conditional: P(rainy∣yes)=P(rainy,yes)P(yes)=0.300.40=0.75P(\text{rainy} \mid \text{yes}) = \dfrac{P(\text{rainy}, \text{yes})}{P(\text{yes})} = \dfrac{0.30}{0.40} = 0.75.
  3. Compare with the base rate: P(rainy)=0.40P(\text{rainy}) = 0.40. Knowing someone carries an umbrella raises the chance of rain from 40% to 75%.
  4. Independence test: P(rainy)⋅P(yes)=0.40×0.40=0.16P(\text{rainy}) \cdot P(\text{yes}) = 0.40 \times 0.40 = 0.16, but P(rainy,yes)=0.30P(\text{rainy}, \text{yes}) = 0.30. The two are not equal, so the variables are dependent.

Interpretation: the umbrella is evidence about the weather, and the joint is what lets you measure how strong that evidence is.

Example
A spam word and a spam label

A filter looks at one word, "free", in each email, and records whether the email is spam. Across a large sample, the joint probabilities are:

spamnot spamtotal
contains "free"0.200.050.25
no "free"0.100.650.75
total0.300.701.00
  1. Probability an email is spam given it contains "free": 0.200.25=0.80\dfrac{0.20}{0.25} = 0.80.
  2. Probability an email is spam given it lacks "free": 0.100.75≈0.133\dfrac{0.10}{0.75} \approx 0.133.
  3. The ratio of these two is about 6. The word is strong evidence for spam.
  4. Check: the unconditional spam rate is 0.300.30, and the two conditionals average back to it, weighted by how often "free" appears: 0.25×0.80+0.75×0.133=0.300.25 \times 0.80 + 0.75 \times 0.133 = 0.30.

Interpretation: a single word moves the spam probability from 30% to 80% or down to about 13%. The filter is useful because the joint is not independent.

Tradeoffs and failure modes

SituationProblemBetter choice
Many variablesA full discrete joint over nn binary variables needs 2n−12^n - 1 numbers, which grows too fast to estimateFactorise it into conditionals, or assume a structure such as conditional independence
Continuous variables that look roughly bell-shaped togetherA nonparametric joint needs far more data than a parametric oneA [[multivariate-gaussian
Sparse data for some combinationsCells with few counts give noisy conditionalsSmooth the estimates, or pool sparse categories
Assuming independence without checkingJoint probabilities are then wrong, and so are any uncertainty estimatesCheck p(x,y)=p(x) p(y)p(x, y) = p(x)\,p(y) on data before relying on it
Reading a conditional as the reverse conditionalP(spam∣free)P(\text{spam} \mid \text{free}) is not P(free∣spam)P(\text{free} \mid \text{spam})Go back to the joint table and divide by the right margin

The marginals never determine the joint. Two different joints can share the same margins. Take p(0,0)=p(1,1)=12p(0,0) = p(1,1) = \tfrac12 with zeros elsewhere, and compare it with the table where all four cells are 14\tfrac14. Both have margins 12\tfrac12 and 12\tfrac12. The first says XX and YY always agree, and the second says they are independent. Only the joint can tell them apart.

History

Joint probability was implicit in the earliest work on chance. Thomas Bayes's essay, published posthumously in 1763, reasoned about two events at once and about how one changes the probability of the other. Pierre-Simon Laplace used joint and conditional probabilities systematically in the early 1800s. Francis Galton and Karl Pearson developed the bivariate normal and the idea of correlation in the late 1800s, because they needed a precise way to say how two measurements move together. Andrey Kolmogorov's 1933 axioms gave probability a measure-theoretic foundation, which made joint distributions of any number of variables a standard, precise object. The joint became central to modern statistics and machine learning because so many quantities of interest are relationships between variables.

Check yourself

QuestionRecall: What two properties must a joint probability mass function have?Show answer

Every value p(x,y)p(x, y) must be nonnegative, and the values must sum to 1 over all pairs (x,y)(x, y). The first says each entry is a probability, and the second says some pair must occur.

QuestionComputation: Using the umbrella table, what is P(rainy∣yes)P(\text{rainy} \mid \text{yes})?Show answer

P(rainy∣yes)=P(rainy,yes)P(yes)=0.300.40=0.75P(\text{rainy} \mid \text{yes}) = \dfrac{P(\text{rainy}, \text{yes})}{P(\text{yes})} = \dfrac{0.30}{0.40} = 0.75. Divide the joint cell by the marginal for the variable you are conditioning on.

QuestionWhy: Why can't the two marginals alone determine the joint distribution?Show answer

Different joints can have the same row and column totals. Take p(0,0)=p(1,1)=12p(0,0) = p(1,1) = \tfrac12 and compare it with the table where all four cells are 14\tfrac14. Both have margins of 12\tfrac12 and 12\tfrac12, but one has XX and YY always agreeing and the other has them independent. The joint records how the variables relate, and the margins do not.

QuestionApplied: A spam classifier uses 20 binary word features. How many free parameters does a full joint table over those features and the label need, and what assumption makes it practical?Show answer

The features and the label are 21 binary variables, so the full joint needs 221−1=2,097,1512^{21} - 1 = 2{,}097{,}151 numbers. That is far more than any training set can estimate reliably. Naive Bayes assumes the words are independent given the label. Then the joint factorises into one label marginal and one conditional per word and label, which is about 2×20+1=412 \times 20 + 1 = 41 parameters.

Sources