09 / 22 · Several Random Variables
Joint distributions and independence
Recover marginal and conditional laws from a joint model, distinguish zero correlation from independence, and calculate what shared errors leave in an average.
On this page 7
Expectation and variance summarize one random quantity. A prediction task usually observes several: features, a target, a processing cost. Separate summaries do not say which values occur together. To predict one quantity after observing another, we need their joint law.
Consider a fictional population of 36 labeled processing records. Each records two costs, and . We specify their counts below and choose one record uniformly. These are constructed inputs, not measurements of a deployed service.
Joint and marginal distributions#
The joint distribution assigns probabilities to pairs of values. For discrete variables its probability mass function is
The nine possible pairs in our population are not equally likely. Each cell count must be divided by 36. To obtain the marginal distribution of one coordinate, forget the other coordinate by adding all compatible cells:
Joint masses from 36 records
| X / Y | 0 | 2 | 5 | Σ |
|---|---|---|---|---|
| 0 | 6 | 4 | 2 | 12 |
| 1 | 2 | 8 | 2 | 12 |
| 3 | 4 | 2 | 6 | 12 |
| Σ | 12 | 14 | 10 | 36 |
X = 1: (2, 8, 2) / 12 = (1/6, 2/3, 1/6)
Every row contains 12 records, so is uniform on 0, 1 and 3. The column totals are 12, 14 and 10, giving probabilities 1/3, 7/18 and 5/18 for . The table specifies more than these two lists: it records how the coordinates are paired. Many different joint tables can have the same row and column totals.
For a jointly absolutely continuous pair, a nonnegative joint density integrates over regions to give probability. The corresponding marginal formulas are
For a separate continuous example, on the square specify
and zero outside the square. Its values lie between 1/2 and 3/2, and the cross term integrates to zero in either coordinate. Both marginal densities are therefore uniform, equal to 1 on their intervals. Yet the joint density is not constant: uniform marginals alone have not made the pair independent.
Having two continuous marginal densities does not even guarantee a two-dimensional joint density. If is uniform on and , all probability lies on a line segment of area zero. A density with respect to plane area could not assign probability one to that segment. The joint probability law still exists; only that density representation fails.
Conditional distributions#
Observing restricts the discrete population to a row. When , renormalize the row:
In our finite table, selects counts 2, 8 and 2. The conditional probabilities for become 1/6, 2/3 and 1/6. In particular, observing this row changes the probability of cost 2 from 7/18 to 2/3. Adding the unnormalized row masses and conditioning are different operations.
For a joint density and a conditioning value with , the analogous expression is
This is a density ratio, not division by , which is zero for an absolutely continuous variable. For almost every eligible , it integrates to one and reconstructs the joint law when multiplied by . Conditional distributions are determined only up to sets of conditioning values with probability zero; an arbitrary change at one such point does not change the joint law.
Our polynomial example supplies a natural continuous version of this conditional density. Integrating against it gives
At this mean is 11/24, and at it is 13/24. The uniform marginal has mean 1/2, but the conditional mean varies. A conditional distribution need not have a density: in the line-segment example it puts all mass at . Observational conditioning also does not describe what an intervention changing would cause.
Independence of random variables#
Two variables are independent when every event defined by one is independent of every event defined by the other. For all measurable sets and ,
For discrete variables this is equivalent to factorization of every joint mass. For a pair with a joint density, factorization is required almost everywhere:
Equivalently, conditioning leaves the other variable’s distribution unchanged for almost every conditioning value. Checking one cell can refute independence; checking only one favorable cell cannot establish it. Our finite table fails at : its mass is 2/9, while the marginal product is 7/54. In the polynomial model, integrating over the upper-right quarter gives
This compares events with positive area, so it does not mistake a change at a single density point for a distributional difference.
For more than two variables, mutual independence requires joint factorization for the entire collection, not just each pair. The distinction from pairwise independence was established for events in conditional probability. Applying separate measurable functions to independent variables preserves independence. Using the same input in two computations does not provide that guarantee. In supervised learning, a model can use a feature to predict a target precisely because their joint law may fail to factorize.
Covariance and correlation#
Assume finite second moments. Then products are integrable, and covariance measures the expected product of centered deviations:
Large values occurring together contribute positively; a large value paired with a small one contributes negatively. Contributions can cancel, so zero covariance does not mean there is no information in the pairing. The units are the product of the original units. Rescaling and shifting yield
For our 36 records, direct weighted sums give
When both variances are positive, Pearson correlation standardizes this covariance:
It lies between −1 and 1 by the Cauchy–Schwarz inequality. Equality in magnitude means an affine relation with nonzero slope almost surely; the slope determines the sign. Correlation is unchanged by positive rescaling and flips sign if exactly one coordinate’s scale is reversed. It is undefined when either variance is zero. For the finite table its value is positive with square 72/959; the continuous polynomial model has covariance 1/72 and correlation 1/6.
Independence implies zero covariance under these moment assumptions. The converse fails even when both marginal distributions and their variances match exactly. Construct another pair with uniform marginals on and . Give mass 1/6 to each of the four corner pairs and mass 1/3 to . The means and covariance are zero, but the center’s mass is 1/3 instead of the independent value 1/9.
Same marginals and covariance
Dependent, Cov = 0
| X / Y | -1 | 0 | 1 |
|---|---|---|---|
| -2 | 1/6 | 0 | 1/6 |
| 0 | 0 | 1/3 | 0 |
| 2 | 1/6 | 0 | 1/6 |
Independent, Cov = 0
| X / Y | -1 | 0 | 1 |
|---|---|---|---|
| -2 | 1/9 | 1/9 | 1/9 |
| 0 | 1/9 | 1/9 | 1/9 |
| 2 | 1/9 | 1/9 | 1/9 |
The four corner products cancel. Knowing that nevertheless reveals with certainty. This dependence is visible in the full table and invisible to its covariance. Correlation also supplies no causal direction; changing the data-selection process can change association without identifying an intervention effect.
Averaging correlated estimates#
For finite-variance estimates , expand the square of the centered sum:
If every variance is and every distinct pair has correlation , the diagonal and off-diagonal terms give
Averaging reduces individual noise, but a shared component can remain. Specify independent fair signs , each taking −1 and 1, and measurements of a fixed :
Every measurement has variance 5; each pair has covariance 1 and correlation 1/5. The average retains , so its variance is : 5, 2, 5/4 and 17/16 for sample sizes 1, 4, 16 and 64. The limiting variance is 1. This is a specified random-error model, not an empirical claim about a particular model ensemble. A fixed bias would instead affect the mean; reducing variance alone would not remove that bias.
Negative correlations can improve an average, but cannot be held arbitrarily negative as its size grows. Nonnegativity of the equal-correlation formula requires for . At the boundary, let four independent fair signs be centered by their own sample mean: . Their individual variance is 3/4, pair covariance −1/4 and correlation −1/3. Their average is exactly zero. A fixed negative correlation cannot describe an arbitrarily long sequence with equal positive variances.
Sums of independent variables#
Linearity adds means without independence. Variances add for pairwise uncorrelated finite-variance variables; independence is sufficient but stronger. To recover an entire sum distribution from the marginals alone, we do use independence.
For discrete and , list every pair producing , multiply its marginal masses, then add the disjoint alternatives. This operation is convolution:
Specify independent costs with probabilities 2/3, 1/3, and with probabilities 1/2, 1/3, 1/6. The resulting law is
| Sum | 1 | 3 | 4 | 6 | 9 |
|---|---|---|---|---|---|
| Probability | 1/3 | 2/9 | 1/6 | 2/9 | 1/18 |
Sum 6 has two paths: and , each with probability 1/9. The mean of the sum is 7/2. Adding the two input probability lists position by position would not describe these events.
For independent variables with densities, the same operation integrates over the possible first value:
The densities are zero outside their supports; equivalently, integrate only where both factors can be nonzero. Without independence, use the joint law instead of multiplying marginals. Repeated convolution need not make an unscaled sum normal. The later central limit theorem gives conditions and the centering and scaling needed for a normal limit.
What changed#
A pair carries both individual distributions and their pairing. Summation forgets a coordinate, conditioning renormalizes the eligible cases, and independence is a factorization of the whole joint law. Covariance compresses this information to one weighted average, which explains both its usefulness for variance calculations and its inability to detect every dependence.
Limitations#
The finite populations and polynomial density are teaching models, not fitted descriptions of real costs. A joint density is an assumption beyond continuous marginals. Conditional laws at null values need a specified version; finite-row division does not define them. Covariance needs moments, and correlation needs nonzero variance as well. Sample correlation adds estimation uncertainty that the population calculations here do not address. Neither dependence nor conditioning is a causal model.
What you should remember#
- Marginals can be recovered from a joint law; they generally cannot reconstruct it.
- Conditional laws describe which outcomes remain plausible after an observation.
- Independence requires the full factorization, not one matching moment.
- Covariance terms determine how shared randomness affects an average.
- Independent sums combine their laws by convolution.
Code#
This exact standard-library calculation reads the explicitly specified 36-record population. It reproduces the conditional row and covariance, without sampling noise or external data.
from fractions import Fraction as F
xs, ys = [0, 1, 3], [0, 2, 5]
counts = [[6, 4, 2], [2, 8, 2], [4, 2, 6]]
records = [(x, y) for i, x in enumerate(xs)
for j, y in enumerate(ys) for _ in range(counts[i][j])]
n = len(records)
ex = F(sum(x for x, y in records), n)
ey = F(sum(y for x, y in records), n)
exy = F(sum(x*y for x, y in records), n)
row = [y for x, y in records if x == 1]
print('Y | X=1:', [str(F(row.count(y), len(row))) for y in ys])
print('means:', ex, ey)
print('covariance:', exy-ex*ey)
Y | X=1: ['1/6', '2/3', '1/6']
means: 4/3 13/6
covariance: 2/3
The complete verifier additionally checks polynomial integrals, the two zero-covariance tables, shared-sign averages, a negative-correlation boundary and the finite convolution. These are exact constructed cases, not measured predictive performance.
Next#
A general joint law contains much more information than its means and covariance. The multivariate Gaussian is an important special family where a mean vector and covariance matrix do determine the law. We next examine what this assumption enables and what it excludes.
References#
- Kyle Siegrist. Joint Distributions, Random: Probability, Mathematical Statistics, and Stochastic Processes. Basic Theory: joint laws, marginals, product measures and density representations.
- Kyle Siegrist. Conditional Distributions. Basic Theory: discrete conditioning, the almost-everywhere qualification, conditional densities and independence.
- Kyle Siegrist. Covariance and Correlation. Definitions, bilinearity, variance of a sum and the correlation inequality/equality cases.
- Kyle Siegrist. Transformations of Variables. Sums and Convolution: discrete and continuous formulas with support conditions. These are references for mathematical facts; the examples, diagrams and computations above are newly specified. The author’s site declares CC BY 2.0 for the resource; this does not assign that license to our new material or separately credited assets.