standarddeviationcalculator.net

Updated Free · runs in your browser

Statistics

Covariance calculator

Enter pairs of x and y values. The calculator lays out every deviation from the mean, adds the products, and gives the sample and population covariance along with the correlation.

Paired data
xyRemove

One pair per row. Paste two columns from a spreadsheet, or use Add row.

Sample covariance 10.5
Population covariance8.4
Σ(x − x̄)(y − ȳ)42
Pairs n5
Mean x̄6
Mean ȳ7.4
Correlation r0.9105
Directionpositive: x and y tend to rise together
xyx − x̄y − ȳ(x − x̄)(y − ȳ)
23−4−4.417.6
47−2−0.40.8
650−2.40
81022.65.2
101244.618.4
Σ0042
23456789104681012 x y

┄ x̄ and ȳ (dashed)

Show the working, step by step
  1. Find the two means.

    x̄ = 30 ÷ 5 = 6 ȳ = 37 ÷ 5 = 7.4

  2. Multiply each pair of deviations and add the products.

    Σ(x − x̄)(y − ȳ) = 17.6 + 0.8 + 0 + 5.2 + 18.4 = 42

  3. Sample covariance divides by n − 1.

    sxy = 42 ÷ 4 = 10.5

  4. Population covariance divides by n.

    σxy = 42 ÷ 5 = 8.4

  5. Scale by both standard deviations to get the correlation, which lies between −1 and 1.

    r = Σ(x − x̄)(y − ȳ) ÷ √(Σ(x − x̄)² × Σ(y − ȳ)²) = 42 ÷ √(40 × 53.2) = 0.9105

Covariance is in x-units × y-units, so its size depends on the scale of the data. Use r to judge how strong the relationship is.

The formulas

sample: sxy = Σ(x − x̄)(y − ȳ) ÷ (n − 1) population: σxy = Σ(x − x̄)(y − ȳ) ÷ n

Each pair contributes the product of its two deviations. A point up and to the right of the means (both deviations positive) or down and to the left (both negative) adds a positive product. Points in the other two quadrants add negative products. The sign of the total says which pattern dominates.

A worked example

The default data has five pairs. The means are x̄ = 30 ÷ 5 = 6 and ȳ = 37 ÷ 5 = 7.4.

xyx − x̄y − ȳproduct
23−4−4.417.6
47−2−0.40.8
650−2.40
81022.65.2
101244.618.4
Σ0042

sxy = 42 ÷ 4 = 10.5 σxy = 42 ÷ 5 = 8.4

The deviations in each column always add to zero, which is a quick check on the means. With Σ(x − x̄)² = 40 and Σ(y − ȳ)² = 53.2, the correlation is 42 ÷ √(40 × 53.2) = 0.9105, a strong positive linear relationship.

Interpreting covariance

Read the sign, not the size. Positive covariance means the variables rise together, negative means one falls as the other rises. The magnitude is in x-units times y-units (for heights in cm and weights in kg, cm·kg), so it changes whenever you rescale either variable and cannot be compared across data sets. The correlation coefficient fixes that. Covariance is still the building block for regression slopes (b = sxy ÷ sx²), portfolio risk, and principal component analysis.

More than two variables

With three or more variables, the pairwise covariances are collected in a covariance matrix: the variances run down the diagonal and each off-diagonal entry is the covariance of one pair. The matrix is symmetric because cov(x, y) = cov(y, x). To build one, run this calculator on each pair of columns; the sample variance of a single column is its covariance with itself.

Common mistakes

  • Mixing the two denominators. Use n − 1 for a sample, n only when the data is the whole population. Spreadsheets have separate functions for each.
  • Pairing values from different rows. Covariance needs the x and y from the same case.
  • Reading a covariance of zero as "unrelated". y = x² over x = −2 to 2 has zero covariance but a perfect curved relationship.
  • Comparing covariances measured in different units.
Covariance calculator: the worked example on this page, with its result and chart
Covariance calculator: the worked example above, at a glance.

Common questions

What is the difference between sample and population covariance?

Both start from the same sum of products of deviations, Σ(x − x̄)(y − ȳ). Sample covariance divides it by n − 1 and estimates the covariance of a larger population; population covariance divides by n and describes the data you have as the whole population. In Excel these are COVARIANCE.S and COVARIANCE.P.

What does a negative covariance mean?

That when x is above its mean, y tends to be below its mean, and the other way round: the two variables move in opposite directions. A positive covariance means they tend to move together. A covariance near zero means there is no linear tendency either way, though there may still be a curved relationship.

How is covariance related to correlation?

Correlation is covariance divided by the product of the two standard deviations: r = sxy ÷ (sx sy). That removes the units and puts the result between −1 and 1. For the default data, r = 42 ÷ √(40 × 53.2) = 0.9105.

Is a covariance of 10.5 large?

You cannot tell from covariance alone. Its size depends on the units: measure x in centimetres instead of metres and the covariance grows 100-fold while the relationship is unchanged. Use the correlation coefficient to judge strength.

What is the covariance of a variable with itself?

Its variance. Setting y = x in the formula gives Σ(x − x̄)² ÷ (n − 1), the sample variance. That is why the diagonal of a covariance matrix holds the variances.