Statistics & Probability
Advanced

Covariance

Measures how two variables vary together.

Formula

cov(X,Y)=1n∑(xi−xˉ)(yi−yˉ)\text{cov}(X,Y) = \frac{1}{n}\sum (x_i-\bar{x})(y_i-\bar{y})

Variables

x_i,y_iPaired values
\bar{x},\bar{y}Means

Example

Positive = move together

How it works

Covariance measures whether two variables tend to be above or below their own averages at the same time. Each pair contributes a product: if both values are above their means or both are below, the product is positive; if one is above and the other below, the product is negative. Averaging these products gives a single signed value that summarizes the direction of joint variation.

When to use it

Use covariance when you want to check whether two quantitative variables move together and in what direction, such as returns on two assets, study time and test score, or temperature and ice cream sales. It is especially useful as a building block for correlation, regression, and portfolio analysis.

Worked example, step by step

Suppose we have paired data: X = 1, 2, 3 and Y = 2, 0, 4. Step 1: Find the means. \bar{x} = (1+2+3)/3 = 2 \bar{y} = (2+0+4)/3 = 2 Step 2: Compute each deviation product. (1-2)(2-2) = (-1)(0) = 0 (2-2)(0-2) = (0)(-2) = 0 (3-2)(4-2) = (1)(2) = 2 Step 3: Add the products. 0 + 0 + 2 = 2 Step 4: Divide by n = 3. \text{cov}(X,Y) = 2/3 Final answer: \text{cov}(X,Y) = 0.6667 (approximately) Interpretation: the covariance is positive, so larger X values tend to be associated with larger Y values in this dataset.

Common mistakes to avoid

  • Forgetting to subtract the mean from each value before multiplying
  • Assuming covariance has to lie between -1 and 1; that is true for correlation, not covariance
  • Mixing up population and sample formulas and using n when the task requires n-1

Did You Know?

Covariance can be any size, which is why statisticians usually rescale it into the more interpretable correlation.

Share this formula

Reviewed & maintained by the FormulaWon editorial teamLast reviewed September 2026