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.