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.
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
- NIST/SEMATECH e-Handbook of Statistical Methods, 6.5.4.1 Mean Vector and Covariance Matrix — NIST
- Introductory Statistics 2e, §12.4 Testing the Significance of the Correlation Coefficient — OpenStax
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