What this calculator does
Covariance measures whether two variables move together. It is positive when above-average values of one tend to accompany above-average values of the other, and negative when they move oppositely.
Its weakness is that the size is uninterpretable. A covariance of 13.5 says the relationship is positive but nothing about how strong, because the number carries the units of both variables multiplied together. Dividing by the two standard deviations fixes this and gives the correlation coefficient, which for the same data is 0.9718 and immediately means something.
The formula
Each pair of deviations from the two means is multiplied and the products are summed. The sample version divides by n−1 and the population version by n. Both are reported alongside the correlation coefficient, which standardises the covariance by the product of the standard deviations to give a value between −1 and 1.
| Term | Meaning |
|---|---|
| Covariance | The average product of paired deviations from the two means. |
| Correlation | Covariance divided by the two standard deviations, giving a scale-free value from −1 to 1. |
| Sample vs population | The n−1 or n divisor, which changes the covariance but not the correlation. |
| Sign | Positive means the variables move together, negative means oppositely. |
The inputs explained
| Field | What to enter |
|---|---|
| X values | X values, comma or space separated. |
| Y values | Y values, in the same order and the same count as X. |
| Type | Sample for data drawn from a larger population, which is the usual case. |
When to use it
Checking whether two measures relate
The sign of the covariance answers the direction question immediately, even if the magnitude does not help.
Building a portfolio
Covariance between asset returns is the input to portfolio variance, and is used directly rather than standardised.
Preparing for regression
The slope of a simple linear regression is the covariance divided by the variance of X.
Worked examples
Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.
What does covariance look like for different relationships?
Positive, negative and weak relationships compared.
| Y values (X = 1, 2, 3, 4, 5) | Covariance | Direction | Correlation r (standardised covariance) |
|---|---|---|---|
| 10, 8, 6, 4, 2 | -5.000 | Negative: tend to move oppositely | -1.000 |
| 3, 1, 4, 1, 5 | 1.000 | Positive: tend to move together | 0.3536 |
| 2, 4, 6, 8, 10 | 5.000 | Positive: tend to move together | 1.000 |
Questions
What is the difference between covariance and correlation?
Correlation is covariance divided by the product of the two standard deviations. That division removes the units and confines the result to between −1 and 1, making it comparable across data sets. Covariance keeps the units and so cannot be judged without knowing the scales involved.
Does the sample or population version matter?
It changes the covariance, from 13.5 to 10.8 on this calculator default data, but not the correlation, which is 0.9718 either way. The divisor cancels when standardising. Use the sample version unless your data genuinely is the entire population.
Can covariance be zero when the variables are related?
Yes. Covariance detects only linear association. Variables related by a symmetric curve, such as y = x² over a range centred on zero, can have exactly zero covariance while being perfectly determined by each other. Zero covariance means no linear relationship, not independence.
What is a large covariance?
There is no answer without knowing the scales, which is the fundamental limitation. Measuring the same relationship in metres rather than centimetres changes the covariance by a factor of 10,000. If you want a magnitude you can interpret, use the correlation.
For the standardised version, see the correlation coefficient calculator. For a rank-based alternative, see the Spearman’s rank correlation calculator.