Saved

Press the star next to a tool's name to save it.

All my tools

Covariance Calculator

Use this covariance calculator to find the sample and population covariance of paired x and y data, with the means and Pearson's correlation, or from a probability table.

Restored your last values ·

Enter your data as pairs of x and y values, one pair per line, with a space or a comma between them. You get the sample and population covariance, the means and the correlation. For a joint probability table, use the second option and give x, y and the probability on each line.

Everything is worked out in your browser. Nothing you type is sent anywhere.

–

–

Enter your pairs of values, one pair per line, then press Calculate.

A covariance calculator measures how two variables vary together. Enter pairs of x and y values, and you get the sample covariance, the population covariance, the means and Pearson's correlation coefficient. A second mode takes a table of values with their probabilities. A positive covariance means that the variables tend to rise together, and a negative one means that one tends to fall as the other rises. It runs in your browser.

How to use the covariance calculator

  1. Choose paired data or a probability table.
  2. Enter one pair per line: x and y, or x, y and the probability.
  3. Press Calculate.

The definition

The Wikipedia article on covariance defines it as cov(X, Y) = E[(X − E[X])(Y − E[Y])], which simplifies to E[XY] − E[X]E[Y]. For n pairs that are equally likely, this is (1 ÷ n) × the sum of (xᵢ − x̄)(yᵢ − ȳ).[1] In words, take each pair's distance from the two means, multiply the distances, and average the products. Pairs that are above both means, or below both, give positive products, and pairs that are on opposite sides give negative ones.

Sample and population

For a sample, the page gives the formula with 1 ÷ (N − 1) in place of 1 ÷ N, because the population mean is not known and the sample mean is used instead.[1] If the full population is known, you divide by N. The calculator gives both. For the pairs (1, 2), (2, 4), (3, 5), (4, 4) and (5, 5), the means are 3 and 4, the sum of the products of the deviations is 6, the sample covariance is 1.5 and the population covariance is 1.2.

A worked example from the page

The article works an example for a joint probability table. The values of X are 5, 6 and 7, and those of Y are 8 and 9. The probabilities are 0.4 for (6, 8), 0.1 for (7, 8), 0.3 for (5, 9) and 0.2 for (7, 9), with none for the other two cells. The means are 6 and 8.5, and the covariance is −0.1.[1] Choose the table mode and enter one line for each cell with a probability, such as 6 8 0.4, and the calculator gives the same result. The negative sign shows that Y tends to be lower when X is higher.

The sign

The page explains that a positive covariance means that the variables move in the same direction, and a negative one means that they move in opposite directions. Variables with a covariance of zero are called uncorrelated.[1] Independent variables have zero covariance, but the reverse is not true: the page's example is X spread evenly from −1 to 1, with Y = X², which are clearly dependent but have a covariance of zero.[1] The calculator describes the sign in words.

From covariance to correlation

The size of a covariance depends on the units of the variables, so it is hard to read. The Pearson correlation page defines the correlation as the covariance divided by the product of the two standard deviations, which gives a unitless number between −1 and 1.[2] The calculator shows this value too. For the five pairs above, it is 6 ÷ √(10 × 6) = 0.775, a fairly strong positive relation. The page gives the sample form as the sum of the products of the deviations divided by the square root of the product of the two sums of squares.[2]

A numerical caution

The shortcut E[XY] − E[X]E[Y] can lose accuracy when the numbers are large and not centred, since it subtracts two nearly equal numbers. The page warns about this catastrophic cancellation and advises stable methods.[1] The calculator therefore subtracts the means first and then multiplies, so its results stay accurate for data such as years or large amounts.

Uses

Covariance appears in finance, where the covariance of the returns of two assets feeds into the risk of a portfolio, in science, where it shows how two measurements move together, and in statistics, where covariance matrices are the basis of many methods. Use the calculator to find it for a small data set or to check your own work.

How to read the numbers

A covariance of 1.5 does not say much by itself. If x is measured in metres and y in kilograms, the unit is metre-kilograms, and a change to centimetres would change the number a hundredfold. That is why you should look at the correlation, and at a scatter plot of the data, before you draw a conclusion. A covariance can be large because the variables have a large spread, even when the relation between them is weak, and small when the spread is small, even when the relation is strong.

Entering your data

Type or paste one pair on each line, with a space, a tab or a comma between x and y. You can paste two columns from a spreadsheet directly. Make sure that each x is on the same line as its own y, since the order of the pairs matters. Up to 5,000 pairs are accepted. For the probability table, enter every cell that has a probability above zero, and check that the probabilities add up to 1.

Common mistakes

  • Comparing covariances in different units. Use the correlation.
  • Using the wrong divisor. A sample uses n − 1 and a whole population n.
  • Reading zero as independence. Dependent variables can have zero covariance.
  • Unequal lists. Each line must have both an x and a y.

What next

Use this often? Add Covariance to your Home screen.

Frequently asked questions

What is a covariance calculator?

A tool that finds how two variables vary together, as a sample or population covariance, from pairs of values.

What is the covariance formula?

cov(X, Y) = (1 ÷ n) × Σ(xᵢ − x̄)(yᵢ − ȳ) for a population, with n − 1 for a sample.

What does a negative covariance mean?

The variables tend to move in opposite directions: when one is above its mean, the other tends to be below.

What is the difference between covariance and correlation?

Correlation is the covariance divided by the product of the standard deviations. It is unitless and lies between −1 and 1.

Does zero covariance mean independence?

No. Independent variables have zero covariance, but dependent variables can too, such as X and X² for X spread evenly around zero.

What went wrong?

We only receive the reason you pick, never what you typed into the tool.

Thanks for your feedback.

More Math Tools