How to Calculate Covariance

Calculates the covariance as Σ(x − x̄)(y − ȳ) ÷ count. A positive value means y tends to be large when x is large; a negative value means the opposite. List the same number of x and y values.

Covariance measures whether two variables move together. Multiply each pair of deviations from the means and average the results.

sxy=1ni=1n(xixˉ)(yiyˉ)s_{xy} = \dfrac{1}{n}\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y})

The sign is what carries the meaning.

Example

With xx = 1, 2, 3, 4, 5 and yy = 2, 4, 5, 4, 5, the means are xˉ=3\bar{x} = 3 and yˉ=4\bar{y} = 4. The products of the deviations are:

sxy=4+0+0+0+25=65=1.2s_{xy} = \dfrac{4 + 0 + 0 + 0 + 2}{5} = \dfrac{6}{5} = 1.2

The positive result says that yy tends to rise with xx.

Watch out

The size of a covariance means very little on its own. Its units are the units of xx times the units of yy, so switching from centimetres to millimetres multiplies it by ten without changing the relationship at all.

To measure the strength of the relationship, divide the covariance by both standard deviations to cancel the units. That gives the correlation coefficient. In practice, covariance is best seen as the raw material from which correlation is built.