Skip to content

Joint distributions

See two variables together as a cloud, its shadows on the axes as the marginals, and a slice through it as a conditional distribution.

Helps to know firstContinuous random variables

Helps to know first
This topic

First, the picture

Two clouds of points fall, and each casts a shadow on its two axes. Watch the shadows, then look at the clouds.

A cloud and its shadows

1000 pairs of numbers in each cloud, made by a computer (seed 3100).

Two clouds of 1000 points: on the left, two numbers that ignore each other; on the right, a second number that follows the first.

points
0
round: slice mean
–
round: slice spread
–
tilted: slice mean
–
tilted: slice spread
–
0.00 / 8.60 s
Describe this picture

Two panels, side by side on a wide screen and stacked on a phone, each with axes from −3-3 to 33: a “round cloud” and a “tilted cloud”. In each, 1000 seeded points pour into a cloud, and two histograms grow along the edges: one under the cloud, counting the first numbers, and one at its side, counting the second numbers. Both clouds share their first numbers. The left cloud is round. The right cloud is tilted, rising from bottom left to top right. When the points are in, a dotted standard normal bell is drawn over each of the four edge histograms: they look the same. When the clip has finished, a slider, “Slice at x”, places a vertical slice from x−0.25x-0.25 to x+0.25x+0.25, from −3-3 to 33, in both panels at once; its points are lit, and beside each cloud a histogram of their second numbers replaces the shadow, with a dashed mark at the exact slice mean. Readouts give the points in the slice and, for each cloud, their mean and spread. At x=1.5x=1.5 the slice holds 53 points: mean −0.019-0.019 and spread 0.934 on the left, mean 1.192 and spread 0.592 on the right; the exact values are mean 0 and spread 1, and mean 1.2 and spread 0.6.

A cloud and its shadows

So far each random variable has been alone. But measurements often come in pairs: a person’s height and weight, the temperature and the number of ice creams sold, the two parts of a noisy radio signal. To describe a pair I need both numbers at once.

Draw each pair as a point, and many pairs make a cloud. In the picture at the top of the page, the left cloud is round and the right cloud is tilted. In the tilted one, a large first number usually comes with a large second number.

Now look at the edges. The histogram under each cloud counts only the first numbers, as if the cloud cast a shadow straight down. The one at the side counts only the second numbers. Those shadows are the marginal distributions, and in the picture all four are the same bell.

So the shadows do not tell you the cloud. Two very different pairs of variables can have exactly the same marginals. To know how two variables behave together, you need the whole cloud, the joint distribution.

Tables first

The cleanest way to see this is with a table. Let XX be 0 or 1 and YY be 0, 1 or 2. The joint distribution gives the chance of each pair, pXY(x,y)=Pr⁡{X=x, Y=y}p_{XY}(x,y)=\Pr\{X=x,\ Y=y\}:

XX by YYY=0Y=0Y=1Y=1Y=2Y=2row total
X=0X=00.100.200.100.40
X=1X=10.050.150.400.60
column total0.150.350.501

The six chances add up to 1. The shadows are the totals at the edges. Add along a row to get the chance of each value of XX, and down a column for YY:

pX(x)=∑ypXY(x,y),pY(y)=∑xpXY(x,y).p_X(x)=\sum_y p_{XY}(x,y),\qquad p_Y(y)=\sum_x p_{XY}(x,y).

So Pr⁡{X=1}=0.60\Pr\{X=1\}=0.60 and Pr⁡{Y=2}=0.50\Pr\{Y=2\}=0.50. For variables with a density, like the clouds above, the same idea holds with a joint density fXY(x,y)f_{XY}(x,y) and integrals in place of sums.

A slice: the conditional distribution

Now suppose you learn that X=1X=1. Only the second row is still possible. Its chances add up to 0.60, not 1, so divide each by 0.60:

pY∣X(y∣x)=pXY(x,y)pX(x).p_{Y\mid X}(y\mid x)=\frac{p_{XY}(x,y)}{p_X(x)}.

Given X=1X=1, YY is 0, 1 or 2 with chances 0.05/0.6=0.08330.05/0.6=0.0833, 0.15/0.6=0.250.15/0.6=0.25 and 0.40/0.6=0.66670.40/0.6=0.6667. That is the conditional distribution of YY given X=1X=1, the rule of Conditional probability applied to every value at once. Its mean is 0⋅0.0833+1⋅0.25+2⋅0.6667=1.58330\cdot0.0833+1\cdot0.25+2\cdot0.6667=1.5833. Given X=0X=0, the chances are 0.250.25, 0.50.5 and 0.250.25, and the mean is 1.01.0.

In the cloud, a condition is a slice. After the clip, drag the slice to x=1.5x=1.5. In the round cloud, the points in the slice are spread around 0, as if you had learned nothing. In the tilted cloud they sit higher, around 1.2, and closer together. In the clip’s 1000 points, the slice holds 53, with means −0.019-0.019 and 1.192 and spreads 0.934 and 0.592.

The mean of a slice, E{Y∣X=x}\mathbb{E}\{Y\mid X=x\}, is the conditional mean. It is the best guess of YY once you know XX: of all guesses that depend only on xx, it gives the smallest average squared miss. Averaging the slice means with the chances of each slice gives back the overall mean: 0.4⋅1.0+0.6⋅1.5833=1.350.4\cdot1.0+0.6\cdot1.5833=1.35, which is E{Y}=0⋅0.15+1⋅0.35+2⋅0.50\mathbb{E}\{Y\}=0\cdot0.15+1\cdot0.35+2\cdot0.50.

For the clouds in the picture, both variables have mean 0 and spread 1, and the tilt is set by a number ρXY\rho_{XY}, the correlation, which the page Covariance and correlation defines: 0 on the left and 0.8 on the right. For clouds of this kind, the bivariate normal, a slice at xx has

E{Y∣X=x}=μY+ρXY σYσX(x−μX),Var{Y∣X=x}=σY2 (1−ρXY2).\begin{aligned} \mathbb{E}\{Y\mid X=x\}&=\mu_Y+\rho_{XY}\,\frac{\sigma_Y}{\sigma_X}(x-\mu_X),\\ \mathrm{Var}\{Y\mid X=x\}&=\sigma_Y^2\,(1-\rho_{XY}^2). \end{aligned}

With ρXY=0.8\rho_{XY}=0.8 and x=1.5x=1.5, the mean is 0.8⋅1.5=1.20.8\cdot1.5=1.2 and the spread is 1−0.64=0.6\sqrt{1-0.64}=0.6.

Independence is a product

Two variables are independent, as in Independence, when learning one tells you nothing about the other. In a table, that means every slice has the same shape as the shadow. Equivalently, every cell is the product of its row total and its column total:

pXY(x,y)=pX(x) pY(y)for every x,y.p_{XY}(x,y)=p_X(x)\,p_Y(y)\quad\text{for every }x,y.

The table above fails at the first cell: 0.100.10, but 0.40⋅0.15=0.060.40\cdot0.15=0.06. So XX and YY are dependent. Here is the table that has the same totals and is independent:

XX by YYY=0Y=0Y=1Y=1Y=2Y=2row total
X=0X=00.060.140.200.40
X=1X=10.090.210.300.60
column total0.150.350.501

Same shadows, different joint distributions: the table version of the two clouds.

Worked example

  1. A shadow. Pr⁡{Y=2}=0.10+0.40=0.50\Pr\{Y=2\}=0.10+0.40=0.50.
  2. A slice. Pr⁡{Y=2∣X=1}=0.40/0.60=0.6667\Pr\{Y=2\mid X=1\}=0.40/0.60=0.6667.
  3. Dependent. Pr⁡{X=0,Y=0}=0.10\Pr\{X=0,Y=0\}=0.10, but Pr⁡{X=0}Pr⁡{Y=0}=0.06\Pr\{X=0\}\Pr\{Y=0\}=0.06.
  4. Conditional means. Given X=1X=1, the mean of YY is 1.58331.5833; given X=0X=0, it is 1.01.0; overall, 0.4⋅1.0+0.6⋅1.5833=1.350.4\cdot1.0+0.6\cdot1.5833=1.35.
  5. The twin table. With the same totals and independence, the rows are 0.06, 0.14, 0.200.06,\ 0.14,\ 0.20 and 0.09, 0.21, 0.300.09,\ 0.21,\ 0.30.
  6. A cloud slice. With ρXY=0.8\rho_{XY}=0.8, both spreads 1 and both means 0, the slice at x=1.5x=1.5 has mean 1.21.2 and spread 0.60.6.

Where you’ll meet this

A radio receiver’s noise has two parts, in phase and in quadrature, and their joint distribution is a round cloud like the left one. Two sensors that measure the same room share a tilted cloud. Neighbouring pixels in a photograph are a tilted cloud too, which is why one pixel predicts the next so well, and why images compress.

In signal processing · noise clouds and best guesses

The page I/Q and complex baseband draws received symbols as points in a plane, and noise turns each point into a round cloud. The page The Wiener filter makes the best guess of a clean signal from a noisy one; for the bell-shaped noise it assumes, that guess is the conditional mean of this page. One difference in writing: signal processing pages write a random signal in lower case, x[n]x[n], and a density as px(α)p_x(\alpha); here random variables are capitals and a density is fX(x)f_X(x).

Where this leads · the shape of the cloud

The tilted cloud’s oval outline is the picture of a symmetric matrix, its covariance matrix, which Symmetric matrices in the linear algebra course takes apart.

Reference card

QuantityFormulaNotes
JointpXY(x,y)=Pr⁡{X=x, Y=y}p_{XY}(x,y)=\Pr\{X=x,\ Y=y\}density fXY(x,y)f_{XY}(x,y) for continuous
MarginalpX(x)=∑ypXY(x,y)p_X(x)=\sum_y p_{XY}(x,y)the shadow on one axis
ConditionalpY∣X(y∣x)=pXY(x,y)/pX(x)p_{Y\mid X}(y\mid x)=p_{XY}(x,y)/p_X(x)a slice, rescaled
Conditional meanE{Y∣X=x}\mathbb{E}\{Y\mid X=x\}best guess of YY from xx
IndependentpXY=pX pYp_{XY}=p_X\,p_Y everywhereevery slice looks like the shadow
Bivariate normal slicemean μY+ρXYσYσX(x−μX)\mu_Y+\rho_{XY}\frac{\sigma_Y}{\sigma_X}(x-\mu_X), variance σY2(1−ρXY2)\sigma_Y^2(1-\rho_{XY}^2)narrower when ∣ρXY∣\lvert\rho_{XY}\rvert is large
Marginalsdo not fix the jointsame shadows, different clouds

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look