Covariance Calculator

Enter two paired data sets to calculate their covariance.

How it is calculated

Enter the X list and the Y list; values can be separated by commas or spaces. They must have the same count, at least two pairs, and every item must be a number. The tool finds the two means, multiplies each pair of deviations and adds them: S = Σ (xi − x̄)(yi − ȳ). Sample mode divides by n − 1, population mode divides by n. A mode other than population is treated as sample. The result is rounded to two decimals, so a very small covariance such as that of values near 0.001 shows as 0.00. The unit is the unit of X times the unit of Y. The tool also shows the number of pairs. It does not give a correlation coefficient. Row order matters, because values are paired by position.

Worked example

X is the weekly study hours 12, 15, 11, 18, 14 and Y is the grades 3.1, 3.8, 2.9, 4.4, 3.6. The means are 14 and 3.56. Deviations of X: −2, 1, −3, 4, 0. Deviations of Y: −0.46, 0.24, −0.66, 0.84, 0.04. Products: 0.92, 0.24, 1.98, 3.36, 0, which add up to 6.5. Sample mode divides by n − 1 = 4: 6.5 ÷ 4 = 1.625, shown as 1.63 from 5 pairs. Population mode would divide by 5 and give 1.30.

Try this example →

Common mistakes

  • Typing a decimal comma in a list, such as 3,1 for 3.1. A comma separates values, so 3,1 becomes two numbers and the pair count no longer matches.
  • Giving lists of different length, or a text entry like x in the list. Either returns no result.
  • Choosing population mode for data that is only a sample. Population mode divides by n, so the figure is smaller than the sample one, here 1.30 instead of 1.63.
  • Reading covariance as the strength of a relationship. Its size depends on the units, so use correlation to compare relationships, and only the sign tells the direction.
  • Entering the X and Y values in different orders. They are paired by position, so a shuffled Y list gives a different and meaningless answer.

About this calculator

Covariance measures the direction in which two variables move together: a positive covariance means that when one variable is above its mean, the other tends to be above its mean too, while a negative covariance means they tend to move in opposite directions. It is computed as the average of the products of each variable's deviation from its own mean, using either the population formula (dividing by n) or the sample formula (dividing by n − 1, Bessel's correction) depending on whether the data represents an entire population or a sample drawn from it.

Covariance is the building block behind the Pearson correlation coefficient (correlation is covariance normalized by the two variables' standard deviations) and underlies core techniques in finance — such as portfolio variance and the covariance matrix used in Modern Portfolio Theory to diversify risk between assets — as well as in statistics, machine learning (principal component analysis), and the sciences wherever analysts need to quantify how two measured quantities co-vary.

Was this helpful?

You can pick up to 3 reactions.

Be the first to comment.

Popular calculators

All Calculators