2

$X$ and $Y$ are independent random variables uniformly distributed over $[0,1]$. I want to find the CDF of $|X-Y|$. I could use convolution but I wan't to calculate this more "directly". Here is my set-up so far:

Let $Z = |X-Y|$. Then, $F_Z(z) = P(Z \leq z) = P(|X-Y| \leq z)$.

We can split up this last inequality into two cases because of the absolute value:

$P(|X-Y| \leq z) = P(X-Y \leq z, X \geq Y) + P(Y-X \leq z, Y > X)$

We now compute the two terms separately with integration. Let's start with the first term:

To integrate this we need to find the correct limits of integration. The constraints we must satisfy are:

  • $0 \leq x,y \leq 1$
  • $x \geq y$
  • $x - z \leq y$

All of this implies $\max\{x-z,0\} \leq y \leq \min\{1,x\}$. But, $x =1$ at most so we can replace $\min\{1,x\}$ with just $x$:

  • $\implies \max\{x-z, 0\} \leq y \leq x$

We use these boundaries to set up the integral of the first term:

$P(X-Y \leq z , X \geq Y) = \int_0^1{\mathrm{d}x \int_{\max\{x-z,0\}}^x{\mathrm{d}y}}$

Should I continue proceeding this way? Is my set up correct? Thank you!

Did
  • 279,727
David South
  • 2,508
  • 2
    A somewhat simpler approach is to note that the domain defined by the condition $|x-y|\geqslant z$ with $x$ and $y$ in $(0,1)$ corresponds to the union of two triangles (draw them), each with area $\frac12(1-z)^2$, hence $P(|X-Y|\leqslant z)=1-(1-z)^2=2z-z^2$ for every $z$ in $(0,1)$. – Did Oct 17 '15 at 19:43
  • @Did Thank you for this tip. Would you mind expanding this out? I actually just posted another question a few minutes ago asking how to draw these sorts of graphs. I have no idea how to picture the union of two triangles. How do I look at this equation and notice that? – David South Oct 17 '15 at 19:45
  • @Did I'm plotting a bunch of points and it's slowly coming to me! – David South Oct 17 '15 at 19:51
  • 1
    Draw the unit square. For a fixed $z$ between $0$ and $1$, like $z=1/4$, draw the lines $y=x+z$ and $y=x-z$, We want the probability $(X,Y)$ lands in the part of the square between these two lines. This is $1$ minus the probability of landing in the triangle on the upper left, or lower right. – André Nicolas Oct 17 '15 at 19:51
  • @AndréNicolas God you guys are awesome. Thank you so much. I've been playing catch-up in math for a while now since I didn't study at all in high school. I drew the unit square and realized I should have looked at it that way. It makes sense now! – David South Oct 17 '15 at 19:54
  • @AndréNicolas WOOO got it – David South Oct 17 '15 at 20:09
  • https://math.stackexchange.com/questions/1681363/cdf-of-absolute-value-of-difference-in-random-variables?noredirect=1&lq=1 – StubbornAtom Jan 09 '20 at 12:46

2 Answers2

7

Let $Z=|X-Y|$. To determine the density function of the random variable $Z $ we see that

$$ \begin{aligned} \mathbb{P}(Z> z)&=\mathbb{P}(|X-Y|> z)\\ &=\mathbb{P}(X-Y>z)+\mathbb{P}(X-Y<-z)\\ &=\mathbb{P}(X>z+Y)+\mathbb{P}(Y>z+X)\\ &\text{then apply the law of total probability}\\ &=\int_0^{1-z}\mathbb{P}(X> z+y)f_Y(y)dy+\int_0^{1-z}\mathbb{P}(Y>z+x)f_X(x)dx\\ &=\int_0^{1-z}[1-(z+y)]dy+\int_0^{1-z}[1-(z+x)]dx\\ &=(1-z)^2-\left.\frac{y^2}{2}\right|_{y=0}^{1-z}+(1-z)^2-\left.\frac{x^2}{2}\right|_{x=0}^{1-z}\\ &=2\left[(1-z)^2-\frac{(1-z)^2}{2}\right]\\ &=(1-z)^2 \end{aligned} $$ Thus

$$ F_Z(z)=1-\mathbb{P}(Z>z)=1-(1-z)^2=1-1+2z-z^2=2z-z^2 $$ and finally

$$ F_Z(z)=\left\{ \begin{aligned} 0&,\quad z<0\\ 2z-z^2&, \quad 0\leq z<1\\ 1&,\quad z\geq 1 \end{aligned} \right. $$

Joda
  • 366
2

Since $X$ and $Y$ are iid Uniform Random variables, the joint density of $(X, Y)$ is $$f(x,y)=1, \qquad 0<x<1, \qquad 0<y<1 $$ Given that $Z=|X-Y|.$ Assume another variable $U=Y.$
The above set of transformation from $$S_{x,y}=\{(x,y): 0<x<1, 0<y<1 \}$$ to $$S_{Z,U}=\{ (z,u): 0<z<1,0<u<1, z+u\leq 1 \} $$ is not one-to-one.
Consider two sets of transformations:
\begin{eqnarray*} Z_1&=& X-Y, \textrm{ if } X>Y\\ U&=&Y \end{eqnarray*} and \begin{eqnarray*} Z_2&=& Y-X, \textrm{ if }X<Y\\ U&=&Y \end{eqnarray*} These are one-to-one. The solutions to the set of linear equations $z_1=x-y,u=y $ and $z_2=x-y,u=y $ are \begin{eqnarray*} x^{(1)}&=&z_1+u\\ y^{(1)}&=&u \end{eqnarray*} and \begin{eqnarray*} x^{(1)}&=&u-z_2\\ y^{(1)}&=&u \end{eqnarray*} The Jagobians of the first transformation is $1$ and that of second one is $-1.$
The joint density of $(z,u)$ is \begin{eqnarray*} h(z,u)&=&f(x^{(1)},y^{(1)})|J_1|+f(x^{(2)},y^{(2)})|J_2|\\ &=&1+1\\ &=&2, \qquad 0<u<1,\qquad 0<x<1, \mbox{ such that }u+z\leq 1 \end{eqnarray*} The marginal density of $Z$ is $$ h(z)=\int_0^{1-z}h(z,u)du=\int_0^{1-z}2du=2(1-z)$$ The distribution function can be obtained $ F_Z(z)=\int_0^z h(w)dw $ which is

\begin{eqnarray*} F_Z(z)&=&0,\qquad z\leq 0\\ &=& \int_0^z 2(1-w)dw=2z-z^2,\qquad 0\leq w< 1\\ &=& 1 \qquad 1\leq w \end{eqnarray*}