5.3.1 Covariance and Correlation
Consider two random variables and . Here, we define the covariance between and , written . The covariance gives some information about how and are statistically related. Let us provide the definition, then discuss the properties and applications of covariance.
The covariance between and is defined as \begin{align}%\label{} \nonumber \textrm{Cov}(X,Y)&=E\big[(X-EX)(Y-EY)\big]=E[XY]-(EX)(EY). \end{align}
Note that \begin{align}%\label{} \nonumber E\big[(X-EX)(Y-EY)\big]&=E\big[XY-X(EY)-(EX)Y+(EX)(EY)\big]\ \nonumber &=E[XY]-(EX)(EY)-(EX)(EY)+(EX)(EY)\ \nonumber &=E[XY]-(EX)(EY). \end{align} Intuitively, the covariance between and indicates how the values of and move relative to each other. If large values of tend to happen with large values of , then is positive on average. In this case, the covariance is positive and we say and are positively correlated. On the other hand, if tends to be small when is large, then is negative on average. In this case, the covariance is negative and we say and are negatively correlated.
Example Suppose , and given , is exponential with parameter . Find .
- Solution
- We can use Cov. We have and \begin{align}%\label{} \nonumber EY &=E[E[Y|X]] &\big(\textrm{law of iterated expectations (Equation 5.17)}\big)\ \nonumber &=E\left[\frac{1}{X}\right] &\big(\textrm{since }Y|X \sim Exponential(X)\big)\ \nonumber &=\int_{1}^{2} \frac{1}{x} dx\ \nonumber &=\ln 2. \end{align} We also have \begin{align}%\label{} \nonumber EXY &=E[E[XY|X]] &\big(\textrm{law of iterated expectations}\big)\ \nonumber EXY &=E[XE[Y|X]] &\big(\textrm{since} E[X|X=x]=x\big)\ \nonumber &=E\left[X\frac{1}{X}\right] &\big(\textrm{since }Y|X \sim Exponential(X)\big)\ \nonumber &=1. \end{align} Thus, \begin{align}%\label{} \nonumber \textrm{Cov}(X,Y)=E[XY]-(EX)(EY)=1-\frac{3}{2} \ln 2. \end{align}
Now we discuss the properties of covariance.
Lemma The covariance has the following properties:
- ;
- if and are independent then ;
- ;
- ;
- ;
- ;
- more generally,
\begin{align}%\label{} \nonumber \textrm{Cov}\left(\sum_{i=1}^{m}a_iX_i, \sum_{j=1}^{n}b_jY_j\right)=\sum_{i=1}^{m} \sum_{j=1}^{n} a_ib_j \textrm{Cov}(X_i,Y_j). \end{align}
All of the above results can be proven directly from the definition of covariance. For example, if and are independent, then as we have seen before , so \begin{align}%\label{} \nonumber \textrm{Cov}(X,Y)=E[XY]-EX EY=0. \end{align} Note that the converse is not necessarily true. That is, if , and may or may not be independent. Let us prove Item 6 in Lemma 5.3, . We have \begin{align}%\label{} \nonumber \textrm{Cov}(X+Y,Z)&=E[(X+Y)Z]-E(X+Y)EZ\ \nonumber &=E[XZ+YZ]-(EX+EY)EZ\ \nonumber &=EXZ-EXEZ+EYZ-EYEZ\ \nonumber &=\textrm{Cov}(X,Z)+\textrm{Cov}(Y,Z). \end{align} You can prove the rest of the items in Lemma 5.3 similarly.
Example Let and be two independent random variables and \begin{align}%\label{} \nonumber &Z=1+X+XY^2, \ \nonumber &W=1+X. \end{align} Find Cov.
- Solution
- \begin{align}%\label{} \nonumber \textrm{Cov}(Z,W)&=\textrm{Cov}(1+X+XY^2,1+X) \ \nonumber &=\textrm{Cov}(X+XY^2,X) \hspace{80pt}(\textrm{by part 5 of Lemma 5.3}) \ \nonumber &=\textrm{Cov}(X,X)+\textrm{Cov}(XY^2,X) \hspace{44pt}(\textrm{by part 6 of Lemma 5.3}) \ \nonumber &=\textrm{Var}(X)+E[X^2Y^2]-E[XY^2]EX \hspace{12pt}(\textrm{by part 1 of Lemma 5.3 definition of Cov}) \ \nonumber &=1+E[X^2]E[Y^2]-E[X]^2E[Y^2] \hspace{24pt}(\textrm{since and are independent})\ \nonumber &=1+1-0=2. \end{align}
Variance of a sum:
One of the applications of covariance is finding the variance of a sum of several random variables. In particular, if , then \begin{align}%\label{} \nonumber \textrm{Var}(Z)&=\textrm{Cov}(Z,Z)\ \nonumber &=\textrm{Cov}(X+Y,X+Y)\ \nonumber &=\textrm{Cov}(X,X)+\textrm{Cov}(X,Y)+ \textrm{Cov}(Y,X)+\textrm{Cov}(Y,Y)\ \nonumber &=\textrm{Var}(X)+\textrm{Var}(Y)+2 \textrm{Cov}(X,Y). \end{align} More generally, for , we conclude:
\begin{align}\label{eq:var-aX+bY} \textrm{Var}(aX+bY)=a^2\textrm{Var}(X)+b^2\textrm{Var}(Y)+2ab \textrm{Cov}(X,Y) \hspace{20pt} (5.21) \end{align}
Correlation Coefficient:
The correlation coefficient, denoted by or , is obtained by normalizing the covariance. In particular, we define the correlation coefficient of two random variables and as the covariance of the standardized versions of and . Define the standardized versions of and as \begin{align}\label{eq:normalize} U=\frac{X-EX}{\sigma_X}, \hspace{10pt} V=\frac{Y-EY}{\sigma_Y} \hspace{20pt} (5.22) \end{align} Then, \begin{align}%\label{} \nonumber \rho_{XY}=\textrm{Cov}(U,V)&=\textrm{Cov}\left(\frac{X-EX}{\sigma_X},\frac{Y-EY}{\sigma_Y}\right)\ \nonumber &=\textrm{Cov}\left(\frac{X}{\sigma_X},\frac{Y}{\sigma_Y}\right) &(\textrm{by Item 5 of Lemma 5.3})\ \nonumber &=\frac{\textrm{Cov}(X,Y)}{\sigma_X \sigma_Y}. \end{align}
\begin{align}%\label{} \nonumber \rho_{XY}=\rho(X,Y)=\frac{\textrm{Cov}(X,Y)}{\sqrt{\textrm{Var(X) Var(Y)}}}=\frac{\textrm{Cov}(X,Y)}{\sigma_X \sigma_Y} \end{align}
A nice thing about the correlation coefficient is that it is always between and $1$. This is an immediate result of Cauchy-Schwarz inequality that is discussed in Section 6.2.4. One way to prove that is to use the following inequality: \begin{align}%\label{} \alpha \beta \leq \frac{\alpha^2+\beta^2}{2}, \textrm{for }\alpha,\beta \in \mathbb{R}. \end{align} This is because . The equality holds only if . From this, we can conclude that for any two random variables and , \begin{align}%\label{} E[UV] \leq \frac{EU^2+EV^2}{2}, \end{align} with equality only if with probability one. Now, let $ U$ and be the standardized versions of and as defined in Equation 5.22. Then, by definition . But since , we conclude \begin{align}%\label{} \rho_{XY}=E[UV] & \leq \frac{EU^2+EV^2}{2}=1, \end{align} with equality only if . That is, \begin{align}%\label{} \frac{Y-EY}{\sigma_Y}=\frac{X-EX}{\sigma_X}, \end{align} which implies \begin{align}%\label{} Y&=\frac{\sigma_Y}{\sigma_X} X+ \left(EY-\frac{\sigma_Y}{\sigma_X} EX\right)\ &=aX+b, \hspace{3pt} \textrm{where and are constants.} \end{align} Replacing by , we conclude that \begin{align}%\label{} \nonumber \rho(-X,Y) \leq 1. \end{align} But , thus we conclude . Thus, we can summarize some properties of the correlation coefficient as follows.
Properties of the correlation coefficient:
- ;
- if , then , where ;
- if , then , where ;
- for .
Definition Consider two random variables and :
- If , we say that and are uncorrelated.
- If , we say that and are positively correlated.
- If , we say that and are negatively correlated.
Note that as we discussed previously, two independent random variables are always uncorrelated, but the converse is not necessarily true. That is, if and are uncorrelated, then and may or may not be independent. Also, note that if and are uncorrelated from Equation 5.21, we conclude that .
If and are uncorrelated, then \begin{align}%\label{} \nonumber \textrm{Var}(X+Y)=\textrm{Var}(X)+\textrm{Var}(Y). \end{align} More generally, if are pairwise uncorrelated, i.e., when , then \begin{align}%\label{} \nonumber \textrm{Var}(X_1+X_2+...+X_n)=\textrm{Var}(X_1)+\textrm{Var}(X_2)+...+\textrm{Var}(X_n). \end{align}
Note that if and are independent, then they are uncorrelated, and so . This is a fact that we stated previously in Chapter 3, and now we could easily prove using covariance.
Example Let and be as in Example 5.24 in Section 5.2.3, i.e., suppose that we choose a point uniformly at random in the unit disc \begin{align}%\label{} \nonumber D={(x,y)|x^2+y^2 \leq 1}. \end{align} Are and uncorrelated?
- Solution
- We need to check whether . First note that, in Example 5.24 of Section 5.2.3, we found out that and are not independent and in fact, we found that \begin{align}%\label{} \nonumber X|Y \hspace{5pt} \sim \hspace{5pt} Uniform(-\sqrt{1-Y^2},\sqrt{1-Y^2}). \end{align} Now let's find . We have \begin{align}%\label{} \nonumber EX &=E[E[X|Y]] &\big(\textrm{law of iterated expectations (Equation 5.17)}\big) \ \nonumber &=E[0]=0 &\big(\textrm{since }X|Y \hspace{5pt} \sim \hspace{5pt} Uniform(-\sqrt{1-Y^2},\sqrt{1-Y^2})\big). \end{align} Also, we have \begin{align}%\label{} \nonumber E[XY] &=E[E[XY|Y]] &\big(\textrm{law of iterated expectations (Equation 5.17)}\big)\ \nonumber &=E[YE[X|Y]] &\big( \textrm{Equation 5.6}\big) \ \nonumber &=E[Y \cdot 0]=0. \end{align} Thus, \begin{align}%\label{} \nonumber \textrm{Cov}(X,Y)=E[XY]-EXEY=0. \end{align} Thus, and are uncorrelated.