Expected Value of Absolute Value of Difference between Two Independent Uniform Random Variables
Let X be Uniform Random Variable on [0,1]. Y is Uniform Random Variable on [0,2]. Given that X and Y are independent, calculate E[|X-Y|].
I have tried calculating the answer using two different methods - both of which I think are correct approaches - but each produces differing results of 2/3 and 3/4.
Method 1) $$\int_{0}^2\int_{0}^1 (|x-y|/2)dxdy$$ I plug the following into Wolfram Alpha and get 2/3: Wolfram calculation
I'm pretty sure this a correct way of going about getting the expected value, since in general for independent x and y, E[g(x,y)] = $$\int_{a}^b\int_{c}^d g(x,y)f(x)f(y)dxdy$$ where of course f(x) and f(y) are the respective distributions of random variables X and Y, and in this particular instance is (1/2)*(1) = (1/2).
Method 2) E[X-Y|X>Y] + E[Y-X|Y>X]. This method yields me 3/4 when I calculate it. The first integral is $$\int_{0}^1\int_{0}^x (.5(x-y))dydx$$ This equals 1/12. The second integral is $$\int_{0}^2\int_{0}^y (.5(y-x))dxdy$$ This equals 2/3. (2/3) + (1/12) = (3/4).
I'm also fairly certain this is a correct procedure, since there are 3 cases: X>Y, X=Y, and X<Y. X=Y will always produce |X-Y|=0. If X>Y, then |X-Y| = X-Y. If X<Y, then |X-Y| = Y-X. Summing the expectations should yield me a correct result.
Which answer is correct (or neither)? Have I made a careless computational blunder in one of the methods? Or is one of the methods I used a fundamentally incorrect approach to solving the given problem?
EDIT: So, Method 2 is full of errors on my part, which can be noted in the comment section. While I'm certain the correct answer is 2/3, I have found a line of reasoning that yields 3/4 using conditional expectation that I am not able to disprove.
E[|X-Y|] = Pr(Y>1)(E[Y-X|Y>1]) + Pr(X>Y)(E[X-Y|X>Y]) + Pr(Y>X And 0<Y<1)*(E[Y-X|Y>X And 0<Y<1])
Pr(Y>1) = 1/2
Pr(X>Y) = 1/4
Pr(Y>X and 0<Y<1) = 1/4
E[Y-X|Y>1] = 1 (this is intuitive if you think about the symmetry)
E[Y-X|Y>X And 0<Y<1] = E[X-Y|X>Y] (once again intuitive by symmetry)
Now, by linearity of expectation, E[X|X>Y] - E[Y|X>Y] = E[X-Y|X>Y] = 0.5. Given what we know about Y, it is fair to treat Y as uniform on [0,1] in this instance. Therefore, if we expect X to be 0.5, then Y is uniform on [0,0.5], giving expectation of 0.25. The same logic applies in reverse to give us E[X|X>Y] = 0.75. You can see integral proof here: OSU Conditional Expectation Slides.
Finally, summing it all up, (1/2)(1) + (1/4)(1/2) + (1/4)*(1/2) = 3/4.
Can anyone see where I went wrong with my logic on the conditional expectation? In general, when you apply the above procedure, I think what is being spit back is actually the average of the means of X and Y. However, I'm unsure where the logic is breaking down.
Can anyone see where I went wrong with my logic on the conditional expectation?
Here it is!
$$\mathbb{E}|X-Y|=\mathbb{P}[X>Y]\mathbb{E}[X|X>Y]-\mathbb{P}[X>Y]\mathbb{E}[Y|X>Y]+\mathbb{P}[X<Y]\mathbb{E}[Y|X>Y]-\mathbb{P}[X<Y]\mathbb{E}[X|X>Y]$$
$$\frac{1}{4}\times \frac{2}{3}-\frac{1}{4}\times \frac{1}{3}+\frac{3}{4}\times \frac{11}{9}-\frac{3}{4}\times \frac{4}{9}=\frac{2}{3}$$
Sketch of calculations:
$$\mathbb{E}[X|X>Y]=2\int_{0}^{1}x\Bigg[\int_{0}^{ x} dy\Bigg]dx=\frac{2}{3}$$
$$\mathbb{E}[Y|X>Y]=2\int_{0}^{1}\Bigg[\int_{0}^{ x} ydy\Bigg]dx=\frac{1}{3}$$
This because looking at a drawing you see that the distribution is uniform over a triangle with area $0.5$
Similar brainstorming for the other probabilities
$$\mathbb{E}[Y|X<Y]=\frac{2}{3}\int_{0}^{1}\Bigg[\int_{x}^{ 2}y dy\Bigg]dx=\frac{11}{9}$$
$$\mathbb{E}[X|X<Y]=\frac{2}{3}\int_{0}^{1}x\Bigg[\int_{x}^{ 2} dy\Bigg]dx=\frac{4}{9}$$
A third way to solve the problem is the following:
$$\mathbb{E}|X-Y|=\mathbb{E}[Max(X,Y)]-\mathbb{E}[min(X,Y)]$$
Let's set $U=Max(X,Y)$ and $V=min(X,Y)$.
It is very easy to calculate the two CDF's
$$F_U(u) = \begin{cases} 0, & \text{if $u<0$ } \\ \frac{u^2}{2}, & \text{if $0\leq u<1$ } \\ \frac{u}{2}, & \text{if $1\leq u<2$ } \\ 1, & \text{if $u \geq2$} \end{cases}$$
$$F_V(v) = \begin{cases} 0, & \text{if $v<0$ } \\ 1-(1-v)(1-\frac{v}{2}), & \text{if $0\leq v<1$ } \\ 1, & \text{if $v \geq1$} \end{cases}$$
now remembering that with non-negative rv we have
$$\mathbb{E}[X]=\int_{0}^{\infty}\bigg[1-F_X\Bigg]dx$$
immediately we get also
$$\mathbb{E}|X-Y|=\mathbb{E}[U]-\mathbb{E}[V]=\frac{13}{12}-\frac{5}{12}=\frac{2}{3}$$