Skip to content
Omnikalc

How do your two variables move together?

Enter the number of pairs and the sums Σx, Σy, Σxy, Σx² and Σy²: get the sample and population covariance, the correlation coefficient, r² and the regression line.

Updated on
Your inputs

Value out of range

Value out of range

Value out of range

Value out of range

Value out of range

Value out of range

Results

Sample covariance (÷ n − 1)

6.0000

Correlation coefficient r

0.7099

Strong linear relationship
Population covariance (÷ n)
5.2500
Coefficient of determination r²
0.5040
Regression slope (y on x)
0.8400
Regression intercept
3.3000

Covariance measures how two variables vary together. When large values of x go with large values of y, the covariance is positive; when large x goes with small y, it is negative; when there is no pattern, it is close to zero. This calculator works from the sums that a spreadsheet gives you quickly, so you can get the covariance, the correlation coefficient and the regression line without entering every pair.

How the calculation works

With n pairs, let Sxy = Σxy − Σx × Σy ÷ n, Sxx = Σx² − (Σx)² ÷ n and Syy = Σy² − (Σy)² ÷ n.

  • Sample covariance = Sxy ÷ (n − 1), and population covariance = Sxy ÷ n
  • Correlation r = Sxy ÷ √(Sxx × Syy)
  • Slope = Sxy ÷ Sxx, and intercept = (Σy − slope × Σx) ÷ n
  • r² is the share of the variation in y explained by the line

Example

With 8 pairs, Σx = 40, Σy = 60, Σxy = 342, Σx² = 250 and Σy² = 520, we get Sxy = 342 − 300 = 42, Sxx = 50 and Syy = 70. The sample covariance is 42 ÷ 7 = 6.0, and the population covariance is 5.25. The correlation is 42 ÷ √3500 = 0.710, so r² is 0.504. The line is y = 3.3 + 0.84 x.

Covariance, correlation and units

A covariance of 6 means little by itself: it would be 6,000 if y were in different units. The correlation removes the units and tells you the strength of the linear relationship, from −1 (perfect negative) to +1 (perfect positive). A value near 0 means no linear relationship, though a curved one could still exist.

Cautions

Correlation does not show cause: two variables may move together because of a third factor, or by chance in small samples. Outliers have a large effect on both covariance and correlation, so plot your data before relying on the numbers. With sums that are large and close to each other, rounding can cause errors, so keep as many digits as possible.

Frequently asked questions

What does covariance tell you?

Whether two variables move together. A positive value means they tend to rise together, a negative value that one rises as the other falls.

Why is covariance hard to interpret?

Its size depends on the units. The correlation coefficient divides it by both standard deviations to give a value between −1 and 1.

Sample or population covariance?

Use the sample covariance (n − 1) when your data are a sample of a larger group, and the population covariance (n) when you have every member.

Where do the sums come from?

From a table or spreadsheet: add the x values, the y values, the products x × y and the squares of x and y.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.