Skip to main content
CalcMax

Covariance Calculator

Result

1.5000

Covariance

Correlation coefficient (r)
0.7746
Mean of the first data set
3.0000
Mean of the second data set
4.0000
Standard deviation of the first data set
1.5811
Standard deviation of the second data set
1.2247
Count
5

Covariance measures whether two paired lists move together: when a value in the first list is above its mean, is the matching value in the second list usually above its mean too? Paste the two lists — one value per line, or separated by semicolons, commas or spaces — and this covariance calculator returns the covariance, its sign, and the Pearson correlation coefficient beside it. Both means and both standard deviations are printed too, so the number can be checked step by step. Nothing is sorted: the first value of one list is paired with the first value of the other, so the order you type them in is part of the input.

Formula

cov = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ divisor, with n − 1 for a sample and n for a population; r = cov ÷ (sₓ × s_y)

xᵢ, yᵢ
The paired values: the i-th number of the first list goes with the i-th number of the second. The two lists must be the same length, and neither is sorted — pairing is by position, so reordering one list changes the answer
x̄, ȳ
The mean of each list, both printed in the result. Each value enters the calculation as a deviation from its own list's mean, which is why subtracting any constant from every value in a list leaves the covariance unchanged
n
How many pairs there are — the length of either list, up to 200 here. It is the divisor for a population covariance and one less than the divisor for a sample
sₓ, s_y
The standard deviation of each list, on the same sample-or-population setting. They are what turn a covariance into the correlation coefficient, and they are printed so that r can be recomputed from the panel alone
cov
The covariance itself: positive when the two lists tend to rise and fall together, negative when one rises as the other falls, near zero when the linear relationship is weak. Its units are the units of x times the units of y
r
The Pearson correlation coefficient, cov ÷ (sₓ × s_y), which cancels those units and lands between −1 and 1. Unlike the covariance it does not change when you rescale a list, and it comes out identical under the sample and population settings

Covariance is the natural summary when two measurements are taken on the same subjects and the question is whether they move in step: height and weight, study hours and marks, temperature and electricity use, the same sensor read at two moments. It is the quantity that the standard deviation generalises to two variables, and it is the ingredient every correlation, regression slope and portfolio-variance formula is built from — so it is worth computing once by hand to see where those come from. Read the sign, not the size: a covariance of 1.5 and one of 150 can describe exactly the same relationship if one list was measured in metres and the other in centimetres. The correlation coefficient printed below is the unit-free version, and that is the number to quote when the strength of the relationship is what matters. Covariance also says nothing about causation, and it only sees straight lines: two lists with a perfect curved relationship can have a covariance of zero.

Worked examples

  1. Five pairs that rise together: covariance 1.5, r = 0.7746

    1. Means: x̄ = (1+2+3+4+5) ÷ 5 = 3, and ȳ = (2+4+5+4+5) ÷ 5 = 4
    2. Deviations from the mean, x: −2, −1, 0, 1, 2; y: −2, 0, 1, 0, 1
    3. Cross products: (−2)(−2) + (−1)(0) + (0)(1) + (1)(0) + (2)(1) = 4 + 0 + 0 + 0 + 2 = 6
    4. Sample divisor n − 1 = 4: covariance = 6 ÷ 4 = 1.5
    5. Standard deviations: 1.5811 and 1.2247, so r = 1.5 ÷ (1.5811 × 1.2247) = 0.7746

    The sign is positive, which is the part covariance is actually read for: above-average values of x pair with above-average values of y. The size — 1.5 — is in units of x times units of y and would change if either list were rescaled, which is why the correlation coefficient is printed next to it. r comes out at 0.7746: a clear upward relationship, but far from a straight line, because the pair (4, 4) sits below the pattern.

  2. The same pairs as a population: covariance 1.2, r unchanged

    1. Same sums: the cross products still total 6 and the means are still 3 and 4
    2. Population divisor n = 5: covariance = 6 ÷ 5 = 1.2 — smaller than the sample value, because the divisor is larger
    3. Both standard deviations shrink for the same reason: 1.4142 and 1.0954
    4. r = 1.2 ÷ (1.4142 × 1.0954) = 0.7746 — the same as before

    Switching the divisor moves the covariance and both standard deviations, but not the correlation: n − 1 cancels against n in that ratio. So the choice between sample and population matters for the covariance and not at all for r, which is worth knowing before you compare a covariance you computed here with one reported elsewhere — two papers can disagree about 1.5 versus 1.2 and agree perfectly about the relationship.

  3. A perfect curve with zero covariance

    1. Means: both lists average to 3
    2. Deviations, x: −2, −1, 0, 1, 2; y: −2, 1, 2, 1, −2
    3. Cross products: 4 − 1 + 0 + 1 − 4 = 0
    4. Covariance: 0 ÷ 4 = 0, and r = 0 ÷ (1.5811 × 1.8708) = 0 as well

    The second list is an upside-down U: 1, 4, 5, 4, 1 is a perfectly regular pattern, and its covariance with 1 to 5 is exactly zero. Covariance only detects straight-line relationships — here the second list rises and then falls, and the positive and negative contributions cancel precisely. A near-zero covariance therefore means 'no linear relationship', never 'no relationship', and it is the reason the scatter plot has not been made obsolete by a single number.

Limitations

Covariance is not a correlation and should not be read as one. Its size depends on the units of both lists, so it cannot be compared across pairs of variables measured on different scales, and it has no upper bound to judge against — only its sign is directly interpretable. It also only measures linear association, so a strong curved relationship can produce a covariance near zero. Because it is computed from paired values it needs the two lists to line up: the two lists must be the same length, and each value is paired with the one in the same position, so a missing or extra entry in one list shifts everything after it. If either list has no variation at all — every value identical — the correlation coefficient is undefined and this page declines to answer rather than printing a division by zero. The lists are capped at 200 pairs, and tokens such as 1,500 are refused rather than guessed at, since a comma between digits is a decimal point in some countries and a thousands separator in others. Nothing here establishes causation: two lists that move together may be responding to a third variable that is not in either of them.

Frequently asked questions

How do you calculate covariance?
Pair the lists up by position, subtract each list's own mean from its values, multiply the two deviations for each pair, add those products, and divide by n − 1 for a sample or n for a population. For x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5 the cross products total 6, so the sample covariance is 6 ÷ 4 = 1.5. Both means, both standard deviations and the result are printed above, so every step can be followed.
Do the two lists have to be the same length?
Yes, and they must also be in the right order — the first value of one list is paired with the first value of the other, and nothing is sorted. That is why this page refuses a mismatched pair of lists instead of padding the shorter one: with 3 values in one list and 2 in the other, there is no way to know which entry is missing, and silently pairing the first two would give a wrong answer that looks completely reasonable. Check that both lists come from the same subjects in the same rows before pasting them.
What does the sign of the covariance mean?
A positive covariance means that when a value sits above the mean of its own list, the paired value tends to sit above the mean of the other list: the two rise and fall together. A negative covariance means the opposite — one above average tends to go with the other below average. A value near zero means there is no straight-line pattern, which is not the same as no relationship at all: the list 1, 4, 5, 4, 1 has a perfectly regular upside-down U shape and a covariance of exactly zero with 1, 2, 3, 4, 5.
Why is the correlation coefficient printed as well?
Because a covariance cannot be read on its own. Its units are the units of the first list multiplied by the units of the second, so measuring one list in centimetres instead of metres multiplies it by 100 without changing anything about the relationship. Dividing by both standard deviations cancels those units and confines the answer to between −1 and 1, which makes it comparable across variables. The covariance is the quantity the algebra is built from; r is the one to quote when someone asks how strong the relationship is.
Why did it refuse when one of my lists is constant?
Because the correlation coefficient would be divided by zero: if every value in a list is identical, that list's standard deviation is zero, and the relationship has no defined strength. The covariance itself is perfectly well defined — it is zero — but the page prints both numbers together, and reporting half an answer would invite the reader to treat a meaningless r as a real one. The same choice is made elsewhere on this site: the coefficient of variation page declines when the mean is not positive rather than printing an undefined ratio.
Should I use the sample or the population divisor?
Use the sample setting, n − 1, when your lists are a sample drawn from something larger and you want to describe the wider group — the usual case. Use the population setting, n, when the lists are the entire group you care about. The choice changes the covariance and both standard deviations but never the correlation coefficient, since n − 1 cancels against n in that ratio. For the five pairs above the covariance is 1.5 as a sample and 1.2 as a population, with r = 0.7746 either way.

References

Related calculators