Docsity

Covariance and Correlation: Understanding the Relationship Between Random Variables, Study notes of Statistics

Toggle sidebar
bg1
Chapter 5. Multiple Random Variables
5.4: Covariance and Correlation
Slides (Google Drive) Alex Tsun Video (YouTube)
In this section, we’ll learn about covariance; which as you might guess, is related to variance. It is a function
of two random variables, and tells us whether they have a positive or negative linear relationship. It also
helps us finally compute the variance of a sum of dependent random variables, which we have not yet been
able to do.
5.4.1 Covariance and Properties
We will start with the definition of covariance: Cov (X, Y ) = E[(X−E[X])(Y−E[Y])]. By LOTUS, we
know this is equal to (where µX=E[X] and µY=E[Y])
X
xX
y
(x−µX)(y−µY)pX,Y (x, y)
Intuitively, we can see the following possibilities:
•x>µX, y > µY⇒(x−µX)(y−µY)>0 (X, Y both above their means)
•x<µX, y < µY⇒(x−µX)(y−µY)>0 (X, Y both below their means)
•x<µX, y > µY⇒(x−µX)(y−µY)<0 (Xbelow its mean, Yabove its mean)
•x>µX, y < µY⇒(x−µX)(y−µY)<0 (Xabove its mean, Ybelow its mean)
So we get a weighted average (by pX,Y ) of these positive or negative quantities. Just with this brief intuition,
we can say that covariance is positive when X, Y are usually both above/below their means, and negative if
they are opposite. That is, covariance is positive in general when increasing one variable leads to an increase
in the other, and negative when increasing one variable leads to a decrease in the other.
Definition 5.4.1: Covariance
Let X, Y be random variables. The covariance of Xand Yis:
Cov (X, Y ) = E[(X−E[X])(Y−E[Y])] = E[X Y ]−E[X]E[Y]
This should remind you of the definition of variance - think of replacing Ywith Xand you’ll see it!
Note: Covariance can be negative, unlike variance.
Covariance satisfies the following properties:
1. If X⊥Y, then Cov (X, Y ) = 0 (but not necessarily vice versa, because the covariance could be
zero but Xand Ycould not be independent).
2. Cov (X, X ) = Var (X). (Just plug in Y=X).
1
pf3
pf4
pf5
pf8

Partial preview of the text

Download Covariance and Correlation: Understanding the Relationship Between Random Variables and more Study notes Statistics in PDF only on Docsity!

Chapter 5. Multiple Random Variables

5.4: Covariance and Correlation

Slides (Google Drive) Alex Tsun Video (YouTube)

In this section, we’ll learn about covariance; which as you might guess, is related to variance. It is a function of two random variables, and tells us whether they have a positive or negative linear relationship. It also helps us finally compute the variance of a sum of dependent random variables, which we have not yet been able to do.

5.4.1 Covariance and Properties

We will start with the definition of covariance: Cov (X, Y ) = E [(X − E [X])(Y − E [Y ])]. By LOTUS, we know this is equal to (where μX = E [X] and μY = E [Y ]) ∑

x

y

(x − μX )(y − μY )pX,Y (x, y)

Intuitively, we can see the following possibilities:

  • x > μX , y > μY ⇒ (x − μX )(y − μY ) > 0 (X, Y both above their means)
  • x < μX , y < μY ⇒ (x − μX )(y − μY ) > 0 (X, Y both below their means)
  • x < μX , y > μY ⇒ (x − μX )(y − μY ) < 0 (X below its mean, Y above its mean)
  • x > μX , y < μY ⇒ (x − μX )(y − μY ) < 0 (X above its mean, Y below its mean)

So we get a weighted average (by pX,Y ) of these positive or negative quantities. Just with this brief intuition, we can say that covariance is positive when X, Y are usually both above/below their means, and negative if they are opposite. That is, covariance is positive in general when increasing one variable leads to an increase in the other, and negative when increasing one variable leads to a decrease in the other.

Definition 5.4.1: Covariance

Let X, Y be random variables. The covariance of X and Y is:

Cov (X, Y ) = E [(X − E [X])(Y − E [Y ])] = E [XY ] − E [X] E [Y ]

This should remind you of the definition of variance - think of replacing Y with X and you’ll see it! Note: Covariance can be negative, unlike variance.

Covariance satisfies the following properties:

  1. If X ⊥ Y , then Cov (X, Y ) = 0 (but not necessarily vice versa, because the covariance could be zero but X and Y could not be independent).
  2. Cov (X, X) = Var (X). (Just plug in Y = X).

2 Probability & Statistics with Applications to Computing 5.

  1. Cov (X, Y ) = Cov (Y, X). (Multiplication is commutative).
  2. Cov (X + c, Y ) = Cov (X, Y ). (Shifting doesn’t and shouldn’t affect the covariance).
  3. Cov (aX + bY, Z) = a · Cov (X, Z) + b · Cov (Y, Z). This can be easily remembered like the distributive property of scalars (aX + bY )Z = a(XZ) + b(Y Z).
  4. Var (X + Y ) = Var (X) + Var (Y ) + 2Cov (X, Y ), and hence if X ⊥ Y , then Var (X + Y ) = Var (X) + Var (Y ) (as we discussed earlier).
  5. Cov

n i=1 Xi,^

∑m j=1 Yi

∑n i=

∑m j=1 Cov^ (Xi, Yj^ ). That is covariance works like FOIL (first, outer, inner, last) for multiplication of sums ((a + b + c)(d + e) = ad + ae + bd + be + cd + ce).

Proof of Covariance Alternate Formula. We will prove that Cov (X, Y ) = E [XY ] − E [X] E [Y ].

Cov (X, Y ) = E [(X − E [X])(Y − E [Y ])] [def of covariance] = E [XY − E [X] Y − XE [Y ] + E [X] E [Y ]] [algebra] = E [XY ] − E [X] E [Y ] − E [X] E [Y ] + E [X] E [Y ] [Linearity of Expectation] = E [XY ] − E [X] E [Y ] [algebra]

Proof of Property 1: Covariance of Independent RVs is 0.

We actually proved in 5.1 already that E [XY ] = E [X] E [Y ] when X, Y are independent. Hence,

Cov (X, Y ) = E [XY ] − E [X] E [Y ] = 0

Proof of Property 6: Variance of Sum of RVs.

We will show that in general, for any RVs X and Y , that

Var (X + Y ) = Var (X) + Var (Y ) + 2Cov (X, Y )

Var (X + Y ) = Cov (X + Y, X + Y ) [covariance with self = variance] = Cov (X, X) + Cov (X, Y ) + Cov (Y, X) + Cov (Y, Y ) [covariance like FOIL] = Var (X) + 2Cov (X, Y ) + Var (Y ) [covariance with self, and symmetry]

Example(s)

Let X and Y be two independent N (0, 1) random variables and: Z = 1 + X + XY 2 W = 1 + X Find Cov(Z, W ).

4 Probability & Statistics with Applications to Computing 5.

The 1st (purple) plot has a perfect negative linear relationship and so the correlation is −1. The 2nd (green) plot has an positive relationship, but it is not perfect, so the correlation is around +0.9. The 3rd (orange) plot is a perfectly linear positive relationship, so the correlation is +1. The 4th (red) plot appears to have data that is independent, so the correlation is 0. The 5th (blue) plot has a negative trend that isn’t strongly linear, so the correlation is around − 0 .6.

Example(s)

Suppose X and Y are random variables, where Y = − 5 X + 2. Show that, since there is a perfect negative linear relationship, ρ(X, Y ) = −1.

Solution To find the correlation, we need the covariance and the two individual variances. Let’s write them in terms of Var (X).

Var (Y ) = Var (− 5 X + 2) = (−5)^2 Var (X) = 25Var (X)

By properties of covariance (shifting by 2 doesn’t matter),

Cov (X, Y ) = Cov (X, − 5 X + 2) = − 5 Cov (X, X) = − 5 Var (X)

Finally,

ρ(X, Y ) = Cov (X, Y ) √ Var (X)

Var (Y )

− 5 Var (X) √ Var (X)

25 Var (X)

− 5 Var (X) 5 Var (X)

Note that the −5 and 2 did not matter at all (except that −5 was negative and made the correlation negative)!

5.4.3 Variance of Sums of Random Variables

Perhaps the most useful application of covariance is in finding the variance of a sum of dependent random variables. We’ll extend the case of Var (X + Y ) to more than two random variables.

5.4 Probability & Statistics with Applications to Computing 5

Theorem 5.4.1: Variance of Sums of RVs

If X 1 , X 2 ,... , Xn are random variables, then

Var

( (^) n ∑

i=

Xi

∑^ n

i=

Var (Xi) + 2

i<j

Cov (Xi, Xj )

Proof of Variance of Sums of RVs. We’ll first do something unintutive - making our expression more complicated. The variance of the sum X 1 + X 2 + · · · + Xn is the covariance with itself! We’ll use i to index one of the sums

∑n i=1 Xi^ and^ j^ for the other^

∑n j=1 Xi. Keep in mind these both represent the same quantity; you’ll see why we used different dummy variables soon!

Var

( (^) n ∑

i=

Xi

= Cov

∑^ n

i=

Xi,

∑^ n

j=

Xj

 (^) [covariance with self = variance]

∑^ n

i=

∑^ n

j=

Cov (Xi, Xj ) [by FOIL]

∑^ n

i=

Var (Xi) + 2

i<j

Cov (Xi, Xj ) [by symmetry (see image below)]

The final step comes from the definition of covariance of a variable with itself and the symmetry of the covariance. It is illustrated below where the red diagonal is the covariance of a variable with itself (which is its variance), and the green off-diagonal are the symmetric pairs of covariance. We used the fact that Cov (Xi, Xj ) = Cov (Xj , Xi) to require us to only sum the lower triangle (where i < j), and multiply by 2 to account for the upper triangle.

It is important to remember than if all the RVs were independent, all the Cov (Xi, Xj ) terms (for i 6 = j) would be zero, and so we would just be left with the sum of the variances as we showed earlier!

5.4 Probability & Statistics with Applications to Computing 7

This is because we need both person i and person j to get their hat back: person i gets theirs back with probability (^) n^1 , and given this is true, person j gets theirs back with probability (^) n^1 − 1

So, by definition of covariance (recall each E [Xi] = (^1) n ):

Cov (Xi, Xj ) = E [XiXj ] − E [Xi] E [Xj ]

=

n

n − 1

n

n

[plug in]

n n^2 (n − 1)

n − 1 n^2 (n − 1) [algebra]

n^2 (n − 1)

[algebra]

Further, since Xi is a Bernoulli (indicator) random variable:

Var (Xi) = p(1 − p) =

n

n

Finally, we have

Var (X) =

∑^ n

i=

Var (Xi) + 2

i<j

Cov (Xi, Xj ) [formula for variance of sum]

∑^ n

i=

n

n

i<j

n^2 (n − 1)

[plug in]

= n

n

n

n 2

n^2 (n − 1)

[there are

n 2

pairs with i < j]

n

n(n − 1) 2

n^2 (n − 1)

n

n = 1

How many pairs are their with i < j? This is just

(n 2

= n(n 2 − 1)since we just choose two different elements. Another way to see this is that there was an n × n square, and we removed the diagonal of n elements, so we are left with n^2 − n = n(n − 1). Divide by two to get just the lower half. This is very surprising and interesting! When returning n hats randomly and uniformly, the expected number of people who get their hat back is 1, and so is the variance! These don’t even depend on n at all! It takes practice to get used to these formula, so let’s do one more problem.

Example(s)

Suppose we throw 12 balls independently and uniformly into 7 bins. What are the mean and variance of the number of empty bins after this process? (Hint: Indicators).

Solution Let X be the total number of empty bins, and X 1 ,... , X 7 be the indicator of whether or not bin i is empty so that X =

i=1 Xi. Then, P (Xi = 1) =

8 Probability & Statistics with Applications to Computing 5.

since we need to avoid this bin (with probability 6/7) 12 times independently. That is,

Xi ∼ Ber

p =

Hence, E [Xi] = p ≈ 0 .1573 and Var (Xi) = p(1 − p) ≈ 0 .1325. These random variables are surely dependent, since knowing one bin is empty means the 12 balls had to go to the other 6 bins, making it less likely that another bin is empty.

However, dependence doesn’t bother us for computing the expectation; by linearity of expectation, we get

E [X] = E

[ 7

i=

Xi

]

∑^7

i=

E [Xi] =

∑^7

i=

Now for the variance, we need to find Cov (Xi, Xj ) = E [XiXj ] − E [Xi] E [Xj ] for i 6 = j. Well, XiXj ∈ { 0 , 1 } since both Xi, Xj ∈ { 0 , 1 }, so XiXj is indicator/Bernoulli as well with

E [XiXj ] = P (XiXj = 1) = P (Xi = 1, Xj = 1) = P (both bin i and j are empty) =

since all the balls must go into the other 5 bins during each of the 12 independent throws. Finally,

Cov (Xi, Xj ) = E [XiXj ] − E [Xi] E [Xj ] =

Recall that Var (Xi) = p(1 − p) ≈ 0 .1325, and so putting this all together gives:

Var (X) =

∑^7

i=

Var (Xi) + 2

i<j

Cov (Xi, Xj ) [formula for variance of sum]

∑^7

i=

i<j

(− 0 .0071) [plug in approximate decimal values]

Recall the hypergeometric RV X ∼ HypGeo(N, K, n) which was the number of lollipops we get when we draw n candies from a bag of N total candies (K ≤ N are lollipops). We stated without proof that

Var (X) = n K(N N^ − 2 (KN)( −N1)^ − n). You have the tools now to prove this if you like using indicators and covariances, but we’ll prove this later in 5.8 as well!