We often want to get a picture of how the relationship between two random variables is. In many cases or more precise in cases where the random variables are independent, we can get a picture of their relationship by inspecting the joint distribution, however that, as already mentioned, just works when the two random variables are independent of each another. In many cases they aren’t. In such cases we use covariance and correlation.
The covariance of two random variables tells us how much these two random variables vary together. In other words: Is there any kind of linear relationship between the two random variables. Pay attention here: Covariance just measures the linear relationship.
If X and Y are random variables with means and respectively, then:
That is because if they have a positive relationship and X has a positive distance from its mean, Y will also have a positive distance from its mean. On the other hand if X has a negative distance from its mean Y will also have a negative distance from its mean. Since minus time minus equals plus, the expectation and therefore the covariance, will be some positive number if X and Y have a positive linear relationship.
On the contrary if X and Y have a negative linear relationship, Y will have a positive distance from its mean if X has a negative distance and vice versa. Therefore the expectation and the covariance will be negative for a negative linear relationship.
If X and Y have joint PMF
If X and Y have joint PDF f(x,y) over range [a,b]x[c,d]
Example: Suppose we toss a fair coin three times. Let X be the number of tails in the first two tosses and Y the number of tails in the last two tosses. Since the two overlap, there should be some covariance. What is the covariance of X and Y?
To answer this we need to have a look at the properties of covariance.
- if a,b,c,d are constants.
- if X and Y are independent: ; that doesn’t imply that if the covariance is 0 X and Y are independent.
Lets go back to our example.
Answer: Based on the given information we can build the following joint probability table:
We can then calculate that E(X)=E(Y)=1 and E(XY)=
The covariance is then:
The problem that occurs now is how to interpret that value. How much do they vary together? Using the covariance one can’t answer that question as the units of the covariance are “units of X times units of Y”. To be able to compare covariances we have to use correlation. The correlation transforms the covariance into a ratio which is always between -1 and 1.
The correlation is denoted “rho” and is calculated as following:
- is a ratio and therefore dimensionless
- if and only if Y=aX+b, a>0
- if and only if Y=aX+b, a<0
The correlation is always between -1 and 1 because the covariance cant exceed the .
Covariance and Correlation are powerful tools and we will see them quite often in the future.