Skip to content
mlmentorship

Expectation, variance, covariance, and correlation

Use moments to describe location, uncertainty, and dependence. Know what covariance measures, how transformations change it, and why correlation does not establish causation.

Published · 10 min read ·Core ·Foundation

Visual quick review

Determine the sign of a covariance contribution from whether each paired observation lies on the same or opposite side of its variable's mean.

Learning objective

Center the population to see spread, co-movement and the limits of correlation

Center the population to see spread, co-movement and the limits of correlationExpectation locates the mean. Variance measures squared spread around it. Covariance averages signed products of joint deviations; same-side points add and opposite-side points subtract. Their pairing changes the spread of a sum even when marginal spreads stay fixed. Changing units alters covariance, not standardized correlation. A curved deterministic relationship can have zero covariance. None of these associations proves causation.Four equally likely outcomes; centeron the meansActual population: two products arepositive, two zeroXYpositive 2positive 2-101-113Means: X zero, Y one. Center herebefore comparing.Rectangles show signed products;circle area shows probability,including repeated locations.Covariance: 1; squared spreads: X 1,Y 2.Keep the marginals; pair X and YindependentlySame X and Y probabilities; differentpairingsXYpositive 2negative 2negative 2positive 2-101-113Means: X zero, Y one. Center herebefore comparing.Rectangles show signed products;circle area shows probability,including repeated locations.Covariance: 0; squared spreads: X 1,Y 2.Pairing changes the spread of the sumOriginal sum variance: 5Independent sum variance: 3Shared variance scale. Positiveco-movement increases sum spreadwithout changing either marginalspread.Change only Y units: values becomeone hundred times largerCovariance: 1 becomes 100. Yvariance: 2 becomes 20000.Correlation: 0.7071 in either unitsystemXYIn standard-deviation units, oldrings and rescaled dots coincide atevery point.Zero covariance can still hide curveddependenceX: minus one, zero, one. Y: one,zero, one.Mean Y: two thirds; signed centeredproducts cancel.XY-101Covariance is zero, but X stilldetermines Y.These are declared populationprobabilities, not empiricalestimates. Correlation does not provecausation.
Read it this way: Expectation locates the mean. Variance measures squared spread around it. Covariance averages signed products of joint deviations; same-side points add and opposite-side points subtract. Their pairing changes the spread of a sum even when marginal spreads stay fixed. Changing units alters covariance, not standardized correlation. A curved deterministic relationship can have zero covariance. None of these associations proves causation. Does multiplying Y's units by one hundred change its correlation?
Full explanation 10 min read
Reading depth

Summary

Expectation averages values under a probability law. Variance averages squared deviations from a mean. Covariance averages products of two variables’ deviations.

Suppose a hypothetical population gives probability to each pair , , and . How does their co-movement affect the spread of ? These are population probabilities, not four observations used to estimate an unknown population.

Covariance

Center both coordinates: the mean of is zero and the mean of is one. Multiply each point’s horizontal and vertical deviations, then average those products.

Reference drawing

Learning objective

Center the population to see spread, co-movement and the limits of correlation

Center the population to see spread, co-movement and the limits of correlationExpectation locates the mean. Variance measures squared spread around it. Covariance averages signed products of joint deviations; same-side points add and opposite-side points subtract. Their pairing changes the spread of a sum even when marginal spreads stay fixed. Changing units alters covariance, not standardized correlation. A curved deterministic relationship can have zero covariance. None of these associations proves causation.Four equally likely outcomes; centeron the meansActual population: two products arepositive, two zeroXYpositive 2positive 2-101-113Means: X zero, Y one. Center herebefore comparing.Rectangles show signed products;circle area shows probability,including repeated locations.Covariance: 1; squared spreads: X 1,Y 2.Keep the marginals; pair X and YindependentlySame X and Y probabilities; differentpairingsXYpositive 2negative 2negative 2positive 2-101-113Means: X zero, Y one. Center herebefore comparing.Rectangles show signed products;circle area shows probability,including repeated locations.Covariance: 0; squared spreads: X 1,Y 2.Pairing changes the spread of the sumOriginal sum variance: 5Independent sum variance: 3Shared variance scale. Positiveco-movement increases sum spreadwithout changing either marginalspread.Change only Y units: values becomeone hundred times largerCovariance: 1 becomes 100. Yvariance: 2 becomes 20000.Correlation: 0.7071 in either unitsystemXYIn standard-deviation units, oldrings and rescaled dots coincide atevery point.Zero covariance can still hide curveddependenceX: minus one, zero, one. Y: one,zero, one.Mean Y: two thirds; signed centeredproducts cancel.XY-101Covariance is zero, but X stilldetermines Y.These are declared populationprobabilities, not empiricalestimates. Correlation does not provecausation.
Derivation
Signs of centered-product contributions to covariance Four equally likely outcomes have X mean zero and Y mean one. Points (-1, -1) and (1, 3) each contribute a centered product of two. Points (-1, 1) and (1, 1) lie on the Y-mean line and contribute zero. Their average product is one. Empty quadrants show where opposite-sign deviations would contribute negatively. X Y mean of X = 0 mean of Y = 1 same signs: (+)(+) = + opposite signs: (-)(+) = - same signs: (-)(-) = + opposite signs: (+)(-) = - 2 (1, 3) 2 (-1, -1) 0 (-1, 1) 0 (1, 1) Cov(X, Y) averages every signed centered product.
Read it this way: each point has probability one quarter. Two centered products equal two; two equal zero. Their average is one. Opposite-sign deviations would contribute negatively.
Check: Why do points with Y equal to its mean contribute zero even when X differs from its mean?
Read it this way: Expectation locates the mean. Variance measures squared spread around it. Covariance averages signed products of joint deviations; same-side points add and opposite-side points subtract. Their pairing changes the spread of a sum even when marginal spreads stay fixed. Changing units alters covariance, not standardized correlation. A curved deterministic relationship can have zero covariance. None of these associations proves causation. Does multiplying Y's units by one hundred change its correlation?

Expectation

For probability mass , . For a density , replace the sum by . Assume finite expectations. For constants , linearity gives

No independence is needed. An expectation need not be a possible outcome: a fair die has expectation .

Variance

Let and . Assume finite second moments. Variance squares one deviation; covariance multiplies two:

Expanding these expressions gives and .

Worked example

OutcomeProbabilityCentered product

The means are and . The second moments are and . Thus , and .

Variance of a sum

Square , then average. The two cross-products produce the covariance term:

Here the variance is . Direct check: takes , with mean . Its squared deviations are , averaging . Removing dependence while retaining the marginals would instead give sum variance .

Correlation

Pearson correlation divides covariance by positive standard deviations and :

Here . It is undefined if either variance is zero. Correlation lies between and and does not establish an intervention effect.

Change the measurement

1. Convert the units of Y

New task: replace by without changing the joint observations.

Picture and change: each vertical deviation grows by . Covariance scales once; variance scales twice.

Check: covariance becomes and variance becomes . Correlation stays . A negative rescaling would reverse its sign.

Use when: units change but the underlying association does not.

2. Average correlated measurements

New task: average four variables, each with variance and pairwise correlation .

Picture and change: retain all six pairwise covariances, each equal to . Divide the full sum variance by .

Check: average variance is , not the independent value .

Use when: measurements share a user, environment or disturbance.

Zero covariance can hide dependence

Let be equally likely to be , and let . Both and are zero, so covariance is zero. Yet is determined by . Independence implies zero covariance under these moment conditions; the reverse implication fails.

Try averaging two independent quantities

Independent variables have variances and . Find the variance and standard deviation of their average.

Check your answer

The covariance term is zero. Variance is , and standard deviation is .

Scaling and repeated measurements

For constants , . Translation changes the mean but not spread. Standard deviation scales by . More generally,

For independent measurements with common variance , their mean has variance . Its standard error falls as , not . As another check, variances and covariance give sum variance .

Covariance matrices

For a random vector with mean , the covariance matrix is

The diagonal contains feature variances. Entry contains the covariance between features and .

A covariance matrix is symmetric and positive semidefinite. For any vector ,

This supports PCA, Gaussian models, whitening and uncertainty ellipsoids. Use a scatter plot alongside Pearson correlation: outliers can change it sharply. Spearman correlation instead measures association between ranks; it answers a different question about monotonic relationships.

In an interview

Reconstruct the sum-variance formula by centering and squaring. State the observation law, moment conditions and independence assumptions before simplifying it.

Common mistakes

  • Saying zero correlation means independence.
  • Treating correlation as evidence of intervention effects.
  • Forgetting the covariance term in the variance of a sum.
  • Saying variance scales linearly with the units of .
  • Comparing covariances across variables with very different units.
  • Using Pearson correlation without checking for nonlinearity or outliers.

Practice next

Use these quantities in bias and variance of estimators, SVD and PCA, and the ML math oral.