The fields of mathematics and statistics offer a great many tools to help us in real life. One such tool is covariance, which is a statistical measure of the directional relationship between two variables. One may apply this concept of covariance to anything. Formulas that calculate covariance can give the prediction of how two stocks might perform relative to each other in the future. Applied to historical prices, covariance can definitely help to determine if stocks’ prices tend to move with or against each other. In this topic, the student will learn about the covariance formula and its example. Let us begin learning!
Covariance Formula
What is Covariance?
In mathematics as well as in statistics, covariance is a measure of the relationship between two random variables in certain problems. This evaluates how much and to what extent the variables change together.
Therefore, it is essentially a measure of the variance between two given variables and also note that the variance of one variable equals the variance of the other variable.
This variance can take any positive or negative values. The values are interpreted as follows:
- Positive covariance: It indicates that two variables will tend to move in the same direction.
- Negative covariance: It indicates that two variables will tend to move in inverse directions.
The formula for Covariance:
The covariance formula deals with the calculation of data points from the average value in a given data collection.
The covariance between two random variables X and Y can be calculated using the following formula as given below:
cov(x,y)=\(\frac{\sum_{i=1}^{N}(x_{i}-\bar{x})(y_{i}-\bar{y})}{N-1}\)
Where:
\(x_i\) | the values of the X-variable |
\(y_i\) | the values of the Y-variable |
\(\bar{x}\) | the mean (average) of the X-variable |
\(\bar{y}\) | the mean (average) of the Y-variable |
N | Â the number of data points |
Cov (x,y) | The covariance of x and y |
In this formula, we can see that the covariance of the two variables x and y is equal to the sum of the products of the differences of each value and the mean of its variables and finally divided by one less than the total number of data points. The x and y with a bar on the represent the means of each variable.
Solved Examples
Q.1: Compute the value of covariance i.e cov(x,y) for the given data set.
X | 98 | 87 | 90 | 85 | 95 | 75 |
Y | 15 | 12 | 10 | 10 | 16 | 7 |
Solution:
First, find the mean of each variable.
Thus,
\(\bar{x} = \frac{ (98+87+90+85+95+75)}{6}\)
i.e. \(\bar{x}\)= 88.33.
And, \(\bar{y} = \frac{ (15+12+10+10+16+7)}{6}\)
i.e. \(\bar{y} = 11.67\)
Now, we subtract each value from its respective mean and then multiply these new values together.
\(x-\bar{x}\) | \(y-\bar{y}\) | /((x-\bar{x}) (y-\bar{y})\) |
98-88.33 =9.67 | 15-11.67 = 3.33 | 32.20 |
87-88.33= -1.33 | 12-11.67 = 0.33 | -0.44 |
90-88.33 = 1.67 | 10-11.67 = -1.67 | -2.79 |
85-88.33 = -3.33 | 10-11.67 = -1.67 | 5.56 |
95-88.33 = 6.67 | 16-11.67 = 4.33 | 28.88 |
75-88.33 = -13.33 | 7-11.67 = -4.67 | 62.25 |
The next step is to add all the products together, which is 125.66.
Now, divide the above value by (n-1) i.e by (6 – 1) i.e. 5.
Thus cov (x,y) = \(\frac{125.66}{5}\)
i.e cov (x,y)Â = 25.132
Therefore covariance of this set of data is 25.132. It is positive, so we can say that the two variables x and y will have a positive relationship.
I get a different answer for first example.
I got Q1 as 20.5
median 23 and
Q3 26