01 · Learning path

Covariance

Measures how two variables move together relative to their means; it is the basis of correlation and PCA.

  • statistics
  • probability
  • linear relationship

Covariance tells you how much two random variables vary together around their respective means. It is the basic ingredient for describing a linear relationship between two quantities.

What the sign tells us

The numerical value depends on the units of the variables, so it is rarely interpreted on its own. The sign, however, is informative:

  • Positive: when one variable goes up, the other tends to go up.
  • Negative: when one variable goes up, the other tends to go down.
  • Close to zero: there is no obvious linear trend.

Definition

For a sample of pairs , the sample covariance is

where and are the means of each variable. Each term in the numerator is positive when both values are on the same side of their mean, and negative when they are on opposite sides.

Relationship with variance

If you compute the covariance of a variable with itself, you get its variance:

Example

If you look at advertising spend () and sales () over several months and both rise together, the covariance will be positive. If spend increases and sales fall, it will be negative.

Applications

Covariance appears in portfolio calculations in finance, in the covariance matrix used by PCA, and in the definition of correlation, which is its unit-free version.