Covariance Calculator

This covariance calculator works on two paired lists of the same length. Example: x = 1 to 5 and y = 2, 4, 5, 4, 5 have a sample covariance of 1.5.

Source: Wikipedia – Covariance. Updated: .

Separate with spaces or semicolons; commas also separate values, so use a decimal point (2.5), not a comma; both lists must have the same length.
Separate with spaces or semicolons; commas also separate values, so use a decimal point (2.5), not a comma; both lists must have the same length.
My ToolboxYour inputs are saved in this browser only.

Result

Result
Covariance cov(x, y) = 1.5 (sample, n = 5)
All values
QuantityValue
Number of pairs n5
Mean x̄3
Mean ȳ4
Sum of products Σ(x − x̄)(y − ȳ)6
Covariance1.5
Correlation r0.774597
Calculation steps
  • Means: x̄ = 3, ȳ = 4.
  • Sum of the products of deviations: Σ(x − x̄)(y − ȳ) = 6.
  • cov = 6 / 4 = 1.5.
Positive covariance: the series tend to rise together; negative: one rises when the other falls. Its size depends on the units, so only the correlation r is comparable.

How it is calculated

Covariance measures whether two variables rise and fall together. If it is positive, large x values tend to go with large y values; if it is negative, the opposite holds; near 0 suggests no linear relationship.

Formula and steps

Find the means x̄ and ȳ. For every pair multiply the deviations (x − x̄) and (y − ȳ), add all products and divide by n − 1 for a sample or by n for a fully known population. Dividing the covariance by both standard deviations gives the correlation r.

Worked example

For x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5 we have x̄ = 3 and ȳ = 4. The products of deviations are 4, 0, 0, 0 and 2, which add up to 6. As a sample this gives cov = 6 / 4 = 1.5, as a population 6 / 5 = 1.2.

Frequently asked questions

How do you calculate the covariance of two series?

Find both means, multiply the deviations of each pair, add all products and divide by n − 1 (sample) or n (population).

What does positive or negative covariance mean?

Positive means the series move in the same direction, negative in opposite directions. How strong the link is only shows in the correlation, which divides the covariance by both standard deviations.

Sample or population: which one do I use?

If you only hold a subset of the data, use the sample version with n − 1. The denominator n is correct only when you really have every pair of the population.

Sources and legal basis

As of: · Editorial policy

Related tools