Covariance calculator is used to find the relation between two data sets. This sample covariance calculator can find the mean, statistical sum of squares, and covariance of data sets x and y.
What is covariance?
In statistics, a measure of the relation of two random variables is known as covariance. It can be positive or negative. A positive covariance indicates that both sets of data values tend to move in a similar direction.
While a negative covariance indicates that both data sets move in opposite directions. Covariance and correlation are two main terms used to measure the relationship between two sets of data values.
Covariance formula
The formulas for the sample and population covariance are given below.
Population covariance formula
\( Cov\:\left(X,\:Y\right)=\frac{\sum \left(x_i-\overline{x}\right)\left(y_j-\overline{y}\right)}{N}\)
Sample covariance formula
\( Cov\:\left(X,\:Y\right)=\frac{\sum \left(x_i-\overline{x}\right)\left(y_j-\overline{y}\right)}{N-1}\)
- Σ = summation notation
- xi = set of observations of X
- yj = set of observations of Y
- N = total number of observations
How to calculate covariance?
The calculations of covariance can also be done by using the population and sample covariance calculator above. Follow the below examples to learn how to calculate covariance.
Example
Calculate covariance for the given data sets.
X = 2, 5, 6, 8, 9
Y = 3, 6, 7, 9, 10
Solution
Step 1: First of all, find the sample mean of data sets X & Y.
For X
Sample mean of X = x̅ = \(\frac{2+5+\:6+\:8+\:9}{5}=\frac{30}{5}\)
Sample mean of X = x̅ = 6
For Y
Sample mean of Y = ȳ = \(\frac{3+6+7+9+10}{5}=\frac{35}{5}\)
Sample mean of Y = ȳ = 7
Step 2: Now find the deviation (difference of data values from the mean) of sets X & Y and calculate the square of deviations.
xi | (xi - x̅) | yj | (yj - ȳ) | (xi - x̅) (yj - ȳ) |
2 | 2 – 6 = -4 | 3 | 3 – 7 = -4 | (-4)(-4) = 16 |
5 | 5 – 6 = -1 | 6 | 6 – 7 = -1 | (-1)(-1) = 1 |
6 | 6 – 6 = 0 | 7 | 7 – 7 = 0 | (0)(0) = 0 |
8 | 8 – 6 = 2 | 9 | 9 – 7 = 2 | (2)(2) = 4 |
9 | 9 – 6 = 3 | 10 | 10 – 7 = 3 | (3)(3) = 9 |
Step 3: Calculate the summation of (xi - x̅) (yj - ȳ) terms.
Σ(xi - x̅) (yj - ȳ) = 16 + 1 + 0 + 4 + 9
Σ(xi - x̅) (yj - ȳ) = 30
Step 4: Now divide the above expression by N-1 to get the result of sample covariance.
Σ (xi - x̅) (yj - ȳ) / N-1 = 30/(5-1)
Σ (xi - x̅) (yj - ȳ) / N-1 = 30/4 = 7.5