Covariance Calculator

Sample and population covariance of two variables, with correlation and a step table.

Sample covariance = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ (n − 1); population covariance divides by n instead. A positive value means X and Y rise together, a negative value means one falls as the other rises.

Free, runs in your browser. Nothing you enter is uploaded.

How to use it

  1. Paste the X values and the Y values in the same order.
  2. Read the sample and population covariance.
  3. Check the step table and the correlation to judge strength.

What you enter

What you get

Formula

s_xy = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ (n − 1) | σ_xy = Σ(xᵢ − μx)(yᵢ − μy) ÷ n | r = s_xy ÷ (s_x s_y)

Worked example

Input: X: 2, 4, 6, 8; Y: 3, 7, 5, 10

Result: Sample cov 6.33, population cov 4.75, r = 0.82

X and Y increase together.

Questions

How do you calculate covariance?

Subtract the mean from each X and each Y, multiply the paired deviations, add the products, and divide by n − 1 for a sample (n for a whole population).

What is the difference between covariance and correlation?

Correlation is covariance divided by the product of the two standard deviations. It is unit-free and always between −1 and 1, so it shows strength; covariance only shows direction.

Can covariance be negative?

Yes. Negative covariance means that when one variable is above its mean, the other tends to be below its mean.

When do I divide by n − 1?

When your data are a sample used to estimate the population covariance. Dividing by n − 1 removes the bias.

Limitations

References

Related reading

More Statistics

All free tools · By Dr. Zubair Khalid, DVM, MS, PhD.