[Math] Expectation of absolute difference of two uniform random variables

expected valueprobability

Let $X \sim U(0, 1)$ and $Y \sim U(0, 2)$ be independent random variables. Find $\mathbb{E}[|X – Y|]$.

I found $f_{X}(x) = 1$ and $f_{Y}(y) = 1/2$, and I took an integral to find $P(Y > X) = 3/4$, which means $P(Y \leq X) = 1/4$

Now I guess this is true:

$$\mathbb{E}[|X-Y|]=P(Y>X)\mathbb{E}[Y-X] + P(Y\leq X)\mathbb{E}[X-Y]$$

$$= 0.75\cdot \mathbb{E}[Y – X] + 0.25 \cdot \mathbb{E}[X – Y].$$

But I don't really know how to do the other expectations. Maybe someone can help me? I tried using linearity but it gave me a negative term for $E(X – Y)$ which I think is wrong since this is the case when $X > Y$.

This MSE post gives one approach to solving the problem: Expected value of the absolute value of the difference between two independent uniform random variables?

But I think it's not correct. Here's why. Following this approach, I get

$$E(|X – Y|) = \int_{0}^{2}\int_{0}^{1} \frac{|x – y|}{2} \mathop{dx} \mathop{dy} = \frac{2}{3}.$$

But this is the exact same probability you get if $X \sim U(0, 2)$ and $Y \sim (0, 2)$. You get

$$E(|X – Y|) = \int_0^2\int_0^2 \frac{|x – y|}{4} \mathop{dx}\mathop{dy} = \frac{2}{3}.$$

I guess this doesn't make sense intuitively. Also, the integral of an absolute value has a lot of casework. I was thinking maybe someone can get a quicker solution.

Best Answer

The statement $$\mathbb{E}[|X-Y|]=P(Y>X)\mathbb{E}[Y-X] + P(Y\leq X)\mathbb{E}[X-Y]$$ is not correct. It needs to be $$ \mathbb{E}\big[|X-Y|\big]=P(Y>X)\mathbb{E}\big[Y-X\big \vert Y>X\big] + P(Y\leq X)\mathbb{E}\big[X-Y \big\vert X>Y\big]$$ But the easiest way to do the problem is by using the independence of $X$ and $Y$ and the fact that $f(x,y)=f(x)f(y)$ and then just calculating the integral $$ E(|X - Y|) = \int_{0}^{2}\int_{0}^{1} \frac{|x - y|}{2} \mathop{dx} \mathop{dy} = \frac{2}{3}. $$ which you have already done.