Covariance Calculator

Sample and population covariance of two paired lists of numbers, with the means, the sum of cross-products and the correlation r for context.

Use a point for decimals (1.5), no thousands separators, and separate numbers with spaces or a comma and a space.
Pair each y with the x in the same position. 2 to 2000 pairs.
Use “sample” when the pairs are a subset of a larger group (the usual case).

Results

Covariance (sample, cov = Σ(x − x̄)(y − ȳ) ÷ (n − 1))
0.0075
Population covariance (divide by n)
0.006
Sum of cross-products Σ(x − x̄)(y − ȳ)
0.03
Mean of x
4.1
Mean of y
2.08
Number of pairs (n)
5
Correlation coefficient (r = cov ÷ (sₓ · s_y))
0.5669
Direction
Positive: x and y tend to rise together

How it’s calculated

Covariance measures whether two variables move together. Each pair contributes the product of how far x is above its mean and how far y is above its mean. If large x tends to go with large y, the products are mostly positive and the covariance is positive; if large x goes with small y it is negative; if there is no linear pattern the positive and negative products cancel and the covariance is near zero.

sample covariance: cov(x, y) = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ (n − 1) population covariance: cov(x, y) = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ n correlation r = cov(x, y) ÷ (sₓ · s_y) (cov(x, x) is the variance of x)

The size of a covariance depends on the units of x and y, so it is hard to read on its own. The correlation r rescales it to between −1 and 1 and is shown for context.

Example (NIST/SEMATECH e-Handbook 6.5.4.1): five objects with length x = 4.0, 4.2, 3.9, 4.3, 4.1 and width y = 2.0, 2.1, 2.0, 2.1, 2.2. The means are 4.10 and 2.08. The cross-products of the deviations are 0.008, 0.002, 0.016, 0.004 and 0, which add to Σ = 0.03, so the sample covariance is 0.03 ÷ 4 = 0.0075 (the book’s variance-covariance matrix entry) and the population covariance is 0.03 ÷ 5 = 0.006.

Frequently asked questions

What is the difference between covariance and correlation?

Correlation is covariance divided by the product of the two standard deviations. It has no units and always lies between −1 and 1, while covariance depends on the units of x and y.

Should I divide by n or n − 1?

Use n − 1 (sample covariance) when your pairs are a sample from a larger population, which is the usual case. Use n only if you have every pair in the population.

Does zero covariance mean the variables are independent?

No. It means there is no linear tendency. Two variables can have a strong curved relationship and still have covariance near zero.

Why is my covariance so large?

Covariance grows with the scale of the data. Measuring in millimeters instead of meters multiplies it by 1000. Look at the correlation r when you need a scale-free measure.

Embed this calculator

Add this free calculator to your own website. Copy the code below into your page’s HTML:

Need this calculator branded, changed or built around your own prices?See custom business solutions →

Sources

Formulas are taken from the free public references above. Results are provided “as is” for informational and educational purposes only. See our disclaimer.

Added · Last updated · How we check our calculators

Spotted a mistake or missing option? Report a problem· Suggest a calculator