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 · 3 min read ·Core ·Foundation

Summary

Expectation describes the average value of a random variable under its probability distribution. Variance describes spread around that average. Covariance describes how two variables move together, and correlation rescales covariance to a unit-free value between -1 and 1.

These quantities support loss analysis, uncertainty estimates, feature analysis, Monte Carlo methods, and multivariate models. They describe association under a distribution. They do not prove that changing one variable causes another to change.

Expectation

For a discrete random variable with probability mass function ,

For a continuous variable with density ,

Expectation is linear. For constants and ,

This property does not require and to be independent.

A useful warning: an expected value need not be a likely outcome. The expected value of one fair die roll is 3.5, although 3.5 can never appear.

Variance

Variance is the expected squared distance from the mean:

The computational form is

For constants and ,

Adding a constant changes the mean but not the variance. Scaling by scales standard deviation by and variance by .

Covariance

Covariance measures linear co-movement:

It also has a computational form:

Positive covariance means large values of one variable tend to occur with large values of the other. Negative covariance means they tend to move in opposite directions. Zero covariance means there is no linear association.

Independence implies zero covariance when the expectations exist. Zero covariance does not imply independence. For example, let be symmetric around zero and let . Their covariance is zero, but is fully determined by .

Variance of a sum

For two random variables,

For independent variables, the covariance term is zero. This is why averaging independent measurements reduces variance.

If are independent with variance , then the sample mean has variance

The standard error therefore falls as , not .

Correlation

Pearson correlation standardizes covariance:

Correlation is unit-free and invariant to positive rescaling. It measures linear association. A value near zero can hide a strong nonlinear relationship, and an extreme outlier can change the estimate sharply.

Use a scatter plot with the coefficient. For monotonic but nonlinear association, Spearman rank correlation may be more informative.

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 links covariance to principal component analysis, Gaussian models, whitening, and uncertainty ellipsoids.

Worked example

Suppose and both have variance 4 and covariance 3.

If they were independent, the variance would be 8. Positive covariance makes their sum less stable because both variables tend to move in the same direction.

In an interview

Use this order:

  1. Define expectation, variance, and covariance.
  2. State linearity of expectation.
  3. Derive the variance of a sum.
  4. Explain independence versus zero covariance.
  5. Describe correlation as standardized linear association.
  6. Connect the covariance matrix to variance along a direction.

A common follow-up asks why the standard error falls as . Start from the variance of an average of independent variables.

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.