Covariance Calculator

Enter your x and y values to see how they vary together.

Numbers separated by commas, spaces or new lines.

One y for each x, in the same order.

Try

Result

You enteredx={1, 2, 3, 4}y={2, 4, 6, 8}x = \left\{ 1,\ 2,\ 3,\ 4 \right\} \quad y = \left\{ 2,\ 4,\ 6,\ 8 \right\}

Sample covariance 3.333333, population covariance 2.5\displaystyle \text{Sample covariance } 3.333333,\ \text{population covariance } 2.5

Fraction

103\displaystyle \frac{10}{3}

Mean of x

2.5\displaystyle 2.5

Mean of y

5\displaystyle 5
Show the work
  1. Means of x and y

    Covariance measures how x and y move together around their means, so find the means first. There are n=4n = 4 pairs.

    xˉ=2.5yˉ=5\begin{gathered} \bar{x} = 2.5 \\ \bar{y} = 5 \end{gathered}
  2. Sum of products of deviations

    Each pair contributes the product of its two deviations: positive when both are above or both below their means, negative when one is above and the other below.

    Sxy=∑(x−xˉ)(y−yˉ)=(1−2.5)(2−5)+(2−2.5)(4−5)+(3−2.5)(6−5)+(4−2.5)(8−5)=10\begin{aligned} S_{xy} &= \sum \left(x - \bar{x}\right)\left(y - \bar{y}\right) \\ &= \left(1 - 2.5\right)\left(2 - 5\right) + \left(2 - 2.5\right)\left(4 - 5\right) + \left(3 - 2.5\right)\left(6 - 5\right) + \left(4 - 2.5\right)\left(8 - 5\right) \\ &= 10 \end{aligned}
  3. Covariance

    Divide by n−1n - 1 when the pairs are a sample, and by nn when they are the whole population.

    Using sxy=Sxyn−1,σxy=Sxyns_{xy} = \frac{S_{xy}}{n - 1},\quad \sigma_{xy} = \frac{S_{xy}}{n}

    sxy=103≈3.333333σxy=104=2.5\begin{gathered} s_{xy} = \frac{10}{3} \approx 3.333333 \\ \sigma_{xy} = \frac{10}{4} = 2.5 \end{gathered}
  4. Result

    So the sample covariance is 103≈3.333333\frac{10}{3} \approx 3.333333 and the population covariance is 2.52.5.

Worked examples