What is the distribution of $Z = \left| X -Y \right|$ where $X$ is uniform from 0 to 2 and $Y$ is the nearest integer to X?

40 Views Asked by At

Here is my attempt so far, but by checking my equations numerically, my solution is wrong.

Since $Z = \left| X -Y \right|$, we can start calculating is distribution directly:

$$ \text{P}(Z \lt z) \: = \: \text{P}(\left| X -Y \right| \lt z) \: = \: \text{P}(-z \lt X -Y \lt z) \:=\: \text{P}(\,X -Y \lt z) - \text{P}(\,X -Y \lt -z) $$

With that, all I need to calculate is the CDF of $\;X - Y$. Conditioning on $\; Y$ we have:

$$ \begin{align*} \text{P}(\,X -Y \lt z) &= \sum_{i=0}^2 \text{P}(\,X -y \lt z \;|\; Y = y)\cdot\text{P}(Y=y) \\ &= \sum_{i=0}^2 \text{P}(\,X \lt z + y\;|\; Y = y)\cdot\text{P}(Y=y) \\ &= \text{P}(\,X \lt z \;|\; Y = 0)\cdot\text{P}(Y=0) + \text{P}(\,X \lt z \;+\; 1\;|\; Y = 1)\cdot\text{P}(Y=1) + \text{P}(\,X \lt z \;+\; 2\;|\; Y = 2)\cdot\text{P}(Y=2) \end{align*} $$

That way for each value of $Y=y$ where $y=0,1,2$ we have a different random variable with different ranges and CDFs. For each $y=0,1,2$:

$$ \text{P}(\,X \lt t \;|\; Y = 0) = \int_{0}^t \frac{1}{\frac{1}{2} -0}dx = 2t , \;\;\;\ \text{with }\,\, 0 \lt t \lt \frac{1}{2} $$

$$ \text{P}(\,X \lt t \;|\; Y = 1) = \int_{1/2}^t \frac{1}{\frac{3}{2} - \frac{1}{2}} dx = t -\frac{1}{2}, \;\;\;\ \text{with }\,\, \frac{1}{2} \lt t \lt \frac{3}{2} $$

$$ \text{P}(\,X \lt t \;|\; Y = 2) = \int_{3/2}^t \frac{1}{2 - \frac{3}{2}} dx = 2t - 3, \;\;\;\ \text{with }\,\, \frac{3}{2} \lt t \lt 2 $$

Meaning that each of those is uniformly distributed within those intervals.

So $$ \begin{align*} \text{P}(\,X -Y \lt z) &= \text{P}(\,X \lt z \;|\; Y = 0)\cdot\text{P}(Y=0) + \text{P}(\,X \lt z \;+\; 1\;|\; Y = 1)\cdot\text{P}(Y=1) + \text{P}(\,X \lt z \;+\; 2\;|\; Y = 2)\cdot\text{P}(Y=2) \\ &= \frac{2z}{4} + \frac{2(z+1) - 1}{2} + \frac{2(z+2) - 3}{4} \\ &= \frac{8z + 3}{4} \end{align*} $$

So, in calculating the desired CDF we have

$$ \begin{align*} \text{P}(Z \lt z) \: &= \: \text{P}(\left| X -Y \right| \lt z) \: = \: \text{P}(\,X -Y \lt z) - \text{P}(\,X -Y \lt -z) \\ &= \frac{8z + 3}{4} - \frac{8(-z) + 3}{4} \\ &= 4z \end{align*} $$

Which at this point doesn't seem right. I know I need to reach a uniform distribution between 0 and $\frac{1}{2}$ because this is what I arrived at numerically. But I think I'm not using the intervals of the conditional $X|Y$ properly. What am I doing wrong?