Covariance Calculator
Find the sample (n − 1) and population (n) covariance of two paired lists of numbers, with the pair count, and see why the units make its size hard to read.
Covariance Calculator
Background.
Covariance asks a narrow question of paired data: when one value sits above its own average, does its partner tend to sit above its average too? For each pair you measure how far x is from the mean of the xs and how far y is from the mean of the ys, then multiply the two distances. Pairs on the same side of both means give positive products; pairs that split give negative ones. Add them up and divide by the number of pairs (or one fewer), and the sign tells you which pattern won.
The sign is the easy part. The size is not, because covariance comes out in the units of x multiplied by the units of y — hours times marks, kilograms times centimetres. Record x in centimetres instead of metres and the covariance grows a hundredfold while the relationship stays exactly as it was. So a covariance of 225 is not necessarily a stronger link than one of 2.25; they may be the same data written differently.
That is why covariance usually feeds something else rather than being reported on its own. Divide it by both standard deviations and you have Pearson's correlation, which is unit-free and runs from −1 to 1. Divide it by the variance of x and you have the slope of the least-squares line. In finance it is the term that decides how much two holdings offset each other's swings.
One trap is worth knowing before you start. Covariance only detects a straight-line tendency. Take x = −2, −1, 0, 1, 2 and y = x², a perfect U-shape: the covariance is exactly 0, even though y is completely determined by x. A small result means no linear trend, not no relationship.
What is covariance calculator?
Covariance is the average of the products of paired deviations: for each observation, (x minus the mean of x) times (y minus the mean of y). Averaged over all n pairs it is the population covariance; divided by n − 1 instead it is the sample covariance, the usual estimate when the pairs are drawn from a larger population. It is symmetric, so swapping the two lists gives the same answer, and the covariance of a variable with itself is simply its variance.
How to use this calculator.
- Type or paste the X values into the first box separated by commas, such as 1, 2, 3, 4, 5. Spaces do not matter, but a column pasted one value per line needs commas added between values.
- Enter the Y values in the same order, so the third Y belongs to the third X. Both lists need the same length and at least two pairs, and a trailing comma counts as an empty item that will be refused.
- Leave out thousands separators: 1,200 is read as two values, 1 and 200. Decimals and scientific notation such as 2.5e-3 are fine.
- Use the sample covariance if your pairs are a sample from something larger, the population covariance if they are every case you care about, and check the pair count matches what you meant to enter.
The formula.
Sample covariance is s_xy = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ (n − 1), where x̄ and ȳ are the means of the two lists and n is the number of pairs. Population covariance uses the same sum divided by n. Each term in the sum is one pair's cross-product: positive when both values sit on the same side of their means, negative when they sit on opposite sides, zero when either sits exactly on its mean. Dividing by n − 1 rather than n is Bessel's correction. Deviations measured from the sample's own means come out slightly too small on average, and the smaller divisor compensates so the sample figure is an unbiased estimate of the population value. Because the terms are products, pairs far from both means dominate: one pair 10 units from each mean contributes 100, as much as a hundred pairs one unit away. Adding a constant to every x or y leaves the result unchanged; multiplying every x by k multiplies it by k.
A worked example.
Take five pairs: X = 1, 2, 3, 4, 5 and Y = 2, 3, 5, 4, 6. The X values total 15, so x̄ = 3; the Y values total 20, so ȳ = 4. The deviations from those means are −2, −1, 0, 1, 2 for X and −2, −1, 1, 0, 2 for Y. Multiplying pair by pair gives 4, 1, 0, 0 and 4, a cross-product sum of 9. Divided by n − 1 = 4 that is a sample covariance of 2.25; divided by n = 5 it is a population covariance of 1.8. The pair count shows 5. All of the positive total comes from the two end pairs; the middle pairs contribute nothing because one value in each sits exactly on its mean. That makes the result fragile. Change only the last Y from 6 to 2 and the mean of Y drops to 3.2, the cross-products become 2.4, 0.2, 0, 0.8 and −2.4, and the sample covariance falls to 0.25 — one point wiped out nearly nine-tenths of it.
Frequently asked questions.
Should I report the sample or the population covariance?
Why did my covariance jump when I changed units?
How do I get a correlation coefficient from covariance?
Can two variables be closely related and still have zero covariance?
Why does Excel or NumPy give a different number from mine?
Where is covariance used in finance?
References& sources.
How this page was produced
- Published by
- Quanta Calculator
- Overseen by
- Daniel, Quanta Calculator Researcher
- Primary sources
- 3 cited below
- Method
- s_xy = sum((x_i-xbar)(y_i-ybar))/(n-1)
- Published
- Last verified
Built with AI assistance and verified by automated tests against the cited sources — every worked example on this page is computed by the same code that runs the calculator. How we build and check calculators.
In this category
Embed
Quanta Pro
Paid features are coming later.
- All 1560 calculators remain free
- No billing is enabled