Joint distributions and independence
Joint pmfs and densities, marginal and conditional distributions, independence of random variables, covariance and correlation, averaging correlated estimates, and convolution for the sum of independent variables.
Two variables at once
The topic Expectation and variance summarized one random variable with a few numbers. Linearity already let us add expectations, , without asking how and are related. Variance is less forgiving. Whether two errors tend to strike together decides how much their sum varies. To see that, we need to describe several variables at once.
Roll two fair dice. Let be the first die and the larger of the two. The joint distribution of gives the probability of every pair of values. For discrete variables it is the joint pmf
a table with one cell per pair of values. The cells are nonnegative and sum to 1.
Each of the 36 equally likely rolls lands in the cell . A cell with gets one roll, the one where the second die shows , so it holds . A diagonal cell gets every roll where the second die shows at most , so it holds . A cell with gets nothing.
For continuous variables the table becomes a joint density on the plane, with total volume 1 under its surface. Probabilities are volumes over a region :
A double integral is computed one variable at a time: integrate over with fixed, then over . As in one dimension, a density is not a probability and can exceed 1. A point uniform in the square has density 4 there, since the square's area is .
Marginal distributions
The joint table holds each variable's own distribution. To get , add up row . The events for different are disjoint and together make up . This is the law of total probability from Conditional probability and Bayes' formula, applied to every value at once:
These are the marginal distributions, named after the sums written in the margins of the table. Here is the dice table in units of .
| row sum | |||||||
|---|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 1 | 1 | 6 | |
| 0 | 2 | 1 | 1 | 1 | 1 | 6 | |
| 0 | 0 | 3 | 1 | 1 | 1 | 6 | |
| 0 | 0 | 0 | 4 | 1 | 1 | 6 | |
| 0 | 0 | 0 | 0 | 5 | 1 | 6 | |
| 0 | 0 | 0 | 0 | 0 | 6 | 6 | |
| column sum | 1 | 3 | 5 | 7 | 9 | 11 | 36 |
Every row sums to : the first die is fair. The columns give , so the maximum leans toward large values.
For densities, sums become integrals: . Take a point uniform in the unit disk, with density inside. At a given the integral runs along a vertical chord of length , so
This marginal is not uniform. It is highest at the centre, where the chords are longest.
The way back is closed: marginals do not determine the joint. Many different tables share the same row and column sums. What the marginals lose is exactly how the variables go together.
Conditional distributions
Suppose we learn that . Of the whole table, only row 3 stays possible, and its cells sum to , not to 1. Divide by that sum and the row becomes a distribution of its own, the conditional distribution of given :
This is from the topic Conditional probability and Bayes' formula, with and . Row 3 reads in units of . Dividing by gives and for each of . Slice, then renormalize.
Read backwards, the definition is the multiplication rule for distributions:
Many models specify a joint distribution exactly this way: first draw , then draw given . A language model does it token by token. It never writes down the distribution of a whole sentence, only the distribution of each next token given the ones before it.
For continuous variables the same formulas hold with densities. They also close a gap left by Conditional probability and Bayes' formula. For a continuous the event has probability zero, so could not be defined as a ratio of probabilities. A ratio of densities is fine wherever . In the disk, fix : the joint density is the constant along the chord, so given , is uniform on .
Independent variables
Sometimes learning tells us nothing about . Then every row, once renormalized, is the same distribution: . Multiply both sides by and you get the definition. Random variables and are independent if
with pmfs or with densities. This is independence of events from Conditional probability and Bayes' formula, demanded for every pair of values at once. Variables are independent when their joint distribution is the product of all marginals. That is the first "i" in "i.i.d.": the joint distribution of a dataset is the product of the distributions of its examples.
One cell is enough to prove dependence. In the dice table , while . So the first die and the maximum are dependent. The coordinates of a point in the disk are dependent too: if is near 1, must be near 0. In the unit square the uniform density is , a product of two uniform densities, so the coordinates are independent. A product needs a rectangular region where the density is positive, but a rectangle alone is not enough.
Independence makes expectations of products factor:
In the discrete case the sum of over all cells splits into a product of two separate sums. In particular, for independent variables. The next block needs exactly this.
Covariance and correlation
Independence is all or nothing. Often we want one number instead: do large values of come with large values of ? Write and . The covariance is
The product of deviations is positive when both variables sit on the same side of their means. So the covariance is positive when they tend to rise together and negative when one rises as the other falls. The second form comes from expanding and using linearity, just like . In fact .
Covariance is symmetric and bilinear: shifts drop out, factors come out, sums split.
Expanding this way answers the question we started with:
Variances add exactly when the covariance is zero, and independent variables have zero covariance because . For two independent dice the variance of the sum is .
Covariance carries units: measure in centimetres instead of metres and it grows a hundredfold. The correlation removes them:
It is undefined when either variable is constant. The bounds follow from . Equality, , holds only when exactly, with the sign of . For the dice, , and : a clear linear trend, far from exact.
Averaging correlated estimates
Back to the variance of a sum, now with terms. Bilinearity gives variances plus a covariance for every ordered pair :
Suppose models each give an estimate with variance , and the errors of every pair have correlation . There are ordered pairs, each with covariance . Divide the sum by , which divides the variance by :
With this is : averaging independent estimates cuts the variance times. The law of large numbers will grow out of exactly this. With the second term still vanishes as grows, but the first one is a floor. At , ten models give and a hundred give .
This is why an ensemble of similar models gains little: their errors are correlated. A random forest fights the floor directly. It trains each tree on its own bootstrap sample and picks each split from a random subset of features, so the trees' errors are less correlated. The same floor hides in data. A thousand test examples from fifty users, or a test set full of near-duplicates, shrinks the error bar of a classifier's error rate far less than a thousand independent examples would.
Sums of independent variables
The variance of a sum is one number. Often we need the whole distribution of . For independent and , the event splits into disjoint events , and independence turns each one into a product. The same holds for densities:
This operation on two distributions is called convolution. For two dice it gives the triangular pmf of the sum, for .
For two independent variables the integrand equals 1 when both and lie in , and 0 otherwise. So the density at is the length of the overlap:
A triangle on . Convolve again and three uniforms give a curve made of parabolas. Each new term makes the shape smoother and more bell-like, a hint of the central limit theorem.
Everything in this topic works for any number of variables, but tables explode. Ten binary variables need cells, and a hundred need more than . Models therefore need structure. The most useful family is described completely by the means and the covariances of every pair, collected into one matrix. Linear maps, marginals and conditionals keep it inside the same family. It is the multivariate Gaussian, the subject of the next topic, The multivariate Gaussian.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.