CCalclabhub

Math · 93 calculators

Covariance Calculator

Covariance measures whether two variables move together, and in which direction. A positive value means they tend to rise and fall in step; a negative value means one tends to rise as the other falls. This page works through the population form using five fixed pairs of observations, giving a result you can reproduce with nothing more than a pencil.

Last updated

Population covariance

1.2

Sample covariance
1.5
Mean of X
3
Mean of Y
4

Values update as you type. This calculator covers the single scenario its formula assumes — see Common Mistakes for what it leaves out.

The formula this calculator uses

Cov(X,Y) = Sum((xi - mean x)(yi - mean y)) / n

Cov(X,Y)
The covariance between variables X and Y
xi, yi
The two values in the i-th paired observation
mean x, mean y
The arithmetic average of each variable separately
n
The number of paired observations, which is five here

How to check the result by hand

  1. 1

    Pair the observations and count them

    Write the data as ordered pairs so it is clear which y belongs to which x. Here there are five pairs: (1,2), (2,4), (3,5), (4,4) and (5,5). Both lists must have the same length, and reordering one list without the other will silently change the answer.

  2. 2

    Find the mean of each variable

    Add the x values and divide by five: (1 + 2 + 3 + 4 + 5) / 5 = 3. Do the same for y: (2 + 4 + 5 + 4 + 5) / 5 = 4. Each variable gets its own mean, and the two are computed independently rather than from the pairs as a group.

  3. 3

    Centre each value and multiply within each pair

    Subtract 3 from every x and 4 from every y, giving x deviations of -2, -1, 0, 1, 2 and y deviations of -2, 0, 1, 0, 1. Multiply the two deviations for each pair: 4, 0, 0, 0 and 2. Same-side pairs contribute positively and opposite-side pairs negatively.

  4. 4

    Add the cross-products

    Sum the five products: 4 + 0 + 0 + 0 + 2 = 6. This cross-product sum is the numerator shared by both the population and the sample formula. A quick sanity check is that it should be positive when most pairs sit on the same side of their respective means, as they do here.

  5. 5

    Divide by n or by n minus one

    For the population divide 6 by 5 to obtain a covariance of 1.2. For a sample divide by 4 instead and obtain 1.5, which is larger because the divisor is smaller. State which convention you used, and remember that the result carries the multiplied units of the two original variables.

Common Questions

How does the Covariance Calculator work?

Find the mean of each variable, subtract each mean from its own observations, multiply the two deviations for every pair, add those products and divide by the number of pairs. For the five pairs (1,2), (2,4), (3,5), (4,4) and (5,5) the means are 3 and 4, the cross-products total 6, and the population covariance is 1.2. Dividing by n minus one instead gives the sample covariance of 1.5.

What do I need to enter in the Covariance Calculator?

It takes 10 inputs: X value 1, Y value 1, X value 2, Y value 2, X value 3, Y value 3, X value 4, Y value 4, X value 5, Y value 5. Fields that expect a unit say so next to the label.

Where does Population covariance come from?

It comes from Cov(X,Y) = Sum((xi - meanX)(yi - meanY)) / N — use when the paired observations are the entire group of interest. Centre each variable on its own mean, multiply the deviations pair by pair, sum them and divide by the total count.

What is the most common mistake with the Covariance Calculator?

Using the wrong divisor. Dividing by n when the pairs are a sample understates the population covariance, while dividing by n minus one for a complete population inflates it for no reason. With five pairs the two answers are 1.2 and 1.5, far apart enough that the choice must be made deliberately.

For worked examples, common mistakes and the limits of this formula, read the full How To Calculate The Covariance page.