# Thread: Variance of Y - X

1. ## Variance of Y - X

Let X and Y be discrete random variables with joint probability function p(x,y) given by the following table:

X\Y | 0 _ 1___ p(x)
0 __| 0 _0.2__ 0.2
1 __| 0.4 0.2 __0.6
2 __| 0.2 0 ___0.2
p(y)| 0.6 0.4 ___1

Find the Variance of Y - X.
******
Hi ! I've been staring at this for a over an hour. It shouldn't be hard but I don't see my mistake...These are my calculations:
E(X) = 1(0.6) + 2(0.4) = 1
E(X^2) = 1.4
Var(X) = 0.2

E[Y] = 0.4
E[Y^2] = 0.4
Var[Y] = 0.24

E[XY] = 1(1)(0.2) = 0.2
Cov(X,Y) = 0.152

So Var(X-Y) = Var(X) + Var(Y) - 2Cov(X,Y) = 0.136
Where did I go wrong? Thanks !!!
(ps: sry for the poor table formatting)
*****

2. ## Re: Variance of Y - X

For the expectation, you need to consider that when you are finding the expectation of one variable, you need to exhaust the possibilities for the other variable.

So for E[X] you have three options: 0,1,2. So E[X] = p(x=0)*0 + p(x=1)*1 + p(x=2)*2.

Now because you have two values of y, you need to consider p(x=a|y=0) + p(x=a|y=1) for some p(x=a). When you merge these two together you get p(x=0) = 0.2, p(x=1) = 0.6 and p(x=2) = 0.2 which gives you a different value to what you have obtained above.

Similarly for E[Y] we consider for p(y=a) = p(y=a|x=0) + p(y=a|x=1) + p(y=a|x=2) to calculate a value for p(y=a) in our expectation, so this gives us E[Y] = 0*p(y=0) + 1*p(y=1) = 0.4 (which is what you had anyway).

So E[X] = 1*0.6 + 2*0.2 = 1. E[X^2] = 1*0.6 + 4*0.2 = 1.4. E[Y] = 0.4, Var[Y] = 0.4 - 0.16 = 0.24.

E[XY] = p(x=0 and y=0)*0*0 + p(x=0 and y=1)*0*1 + p(x = 1 and y=0)*1*0 + p(x = 1 and y = 1)*1*1 + p(x = 2 and y = 0)*2*0 + p(x = 2 and y = 1)*2*1
= p(x = 1 and y = 1) + 2*p(x = 2 and y = 1) = 0.2 + 2*0 = 0.2

Cov(X,Y) = E[XY] - E[X]E[Y] = 0.2 - 1*0.4 = -0.2

Var[X-Y] = Var[X] + Var[Y] - 2Cov(X,Y) = 0.4 + 0.24 - 2*0.2 = 1.04 which is what the answer is.

Your mistake was in the covariance calculation which is Cov(X,Y) = E[XY] - E[X]E[Y]

Calculate E[XY] means you need to expand out all possibilities for X and Y (given this is discrete) and then multiply ab*p(x=a and y=b).

This is just a result of calculating g(z) where z = xy (standard expectation formulae).

3. ## Re: Variance of Y - X

Thanks for the excellent clarification