Overview

Covariance measures whether two variables tend to move together. Positive means they rise together, and negative means one rises as the other falls.

This version works from summary values: the mean of X, the mean of Y and the mean of X × Y. Enter the sample size, and 1 to apply the sample correction.

Worked examples

InputsResult
Mean of X15Mean of Y22Mean of (X*Y)340Sample Size (n)120Use sample correction?YesPopulation covariance: 10Sample covariance: 10.08 (n=120)
Show 2 more examples
Mean of X10Mean of Y5Mean of (X*Y)56Sample Size (n)30Use sample correction?YesPopulation covariance: 6Sample covariance: 6.21 (n=30)
Mean of X4Mean of Y8Mean of (X*Y)28Sample Size (n)50Use sample correction?NoPopulation covariance: -4Sample covariance: -4 (n=50)

Population covariance by mean of

With the calculator's starting values, the population covariance is 10. The table shows how it changes with the mean of.

Mean of (X*Y)Population covariance
200-130
250-80
300-30
340starting value10
35020
40070
450120
500170

Other inputs: Mean of X: 15 · Mean of Y: 22 · Sample Size: 120 n. Change them in the calculator above for your own numbers.

How it works

Population covariance is the mean of the products minus the product of the means. The sample covariance multiplies that by n ÷ (n − 1), which corrects for estimating from a sample. Covariance depends on the units of both variables, so its size is hard to interpret. Divide it by both standard deviations to get the correlation.

The formula

Cov(X, Y) = E[XY] − E[X] × E[Y]
E[XY]Mean of X × Y across all pairs
n ÷ (n − 1)Sample correction

Practical tips

  • Means of 15 and 22 with a mean product of 340 give a population covariance of 10, and 10.08 as a sample estimate with n = 120.
  • To get E[XY], multiply each pair, add them up and divide by the number of pairs.
  • With large samples, the sample and population figures are almost the same.

Frequently asked questions

What's the difference between covariance and correlation?

Correlation is covariance scaled to run from −1 to 1, so it can be compared across data sets.

Can covariance be negative?

Yes. It means the variables tend to move in opposite directions.

When should I use the sample correction?

When your data are a sample and you want to estimate the population covariance.