Derive PDF of a random-variable which is a function of other random-variables

probabilityprobability distributions

This problem is from MIT-OCW 6.041 (Spring 2006), Recitation-08.

Alexei is vacationing in Monte Carlo. The amount $X$ (in dollars) he takes to the casino each evening is a random variable with PDF of the form

$$
f_X(x) =
\begin{cases}
ax, & \text{if}\quad 0 \le x \le 40 \\
0, & \text{otherwise}
\end{cases}
$$

At the end of each night, the amount $Y$ that he has when leaving the casino is uniformly distributed between zero and twice the amount that he came with. Find the PDF of Alexei's profit $Y – X$ on a particular night.

My solution(s):

Let $Z = Y – X$, and we are given that
$$
f_{Y|X}(y|x) =
\begin{cases}
1/2x, & \text{if}\quad 0 \le y \le 2x\\
0, & \text{otherwise}
\end{cases}
$$

we can derive,

$$
f_{X,Y}(x,y) =
\begin{cases}
a/2, & \text{if}\quad 0 \le x \le 40 \quad\text{&}\quad 0 \le y \le 2x\\
0, & \text{otherwise}
\end{cases}
$$

Approach-1: deriving the CDF $F_Z (z)$ and taking its partial-derivative w.r.t. $z$ should give $f_Z(z)$.

$$
\begin{align}
P(\{Z \le z\}) & = P(\{Y – X \le z \}) \\
& = P(\{Y \le z + X\}) \\
& = \int_{0}^{40} \int_{0}^{x+z} f_{X,Y}(x,y)\,dy\,dx \\
& = \frac{a}{2} (40z + 800) \quad\text{//this answer is wrong!}
\end{align}
$$

Approach-2: derive joint-PDF $f_{Z,X}(z,x) = f_{Z|X}(z|x)\,f_X (x)$, and use it to derive $f_Z (z)$.

$$
\begin{align}
P(\{Z \le z\}|\{X = x\}) & = P(\{Y – x \le z \}|\{X = x\}) \\
& = P(\{Y \le z + x\}|\{X = x\}) \quad \text{eq.1} \\
\end{align}
$$

Now, for a given $X = x$, we have $ -x \le z \le x$. So, the LHS of eq.1 is
$$
P(\{Z \le z\}|\{X = x\}) = \int_{-x}^{z}{f_{Z|X}(z|x)}\,dz \quad\text{eq.1-1}
$$

and, the RHS of eq.1 is
$$
\begin{align}
P(\{Y \le z + x\}|\{X = x\}) & = \int_{0}^{z+x} f_{Y|X}(y|x)\,dy
& = \frac{x + z}{2x} \quad\text{eq.1-2}
\end{align}
$$

Partially-differentiating both sides of eq.1 w.r.t $z$ by applying the Leibniz-formula on eq.1-1 and eq.1-2 we get,

$$
\begin{align}
\frac{\partial}{\partial z}\Bigl(\int_{-x}^{z}{f_{Z|X}(z|x)}\,dz\Bigr) & = \int_{-x}^{z}{\frac{\partial f_{Z|X}(z|x)}{\partial z}}\,dz + f_{Z|X}(z|x) \frac{\partial z}{\partial z} – f_{Z|X}(-x|x) \frac{\partial (-x)}{\partial z} \\
& = f_{Z|X}(z|x) \Bigr|_{-x}^{z} + f_{Z|X}(z|x) \quad\text{// this is where I got stuck!}
\end{align}
$$

I would like to know:

  • I think the two approaches (or at-least the idea behind them) should work, but I can't see what I am doing wrong?
  • Is there a better way to compute $f_Z (z)$?

PS: the solution to this problem is

$$
f_Z (z) =
\begin{cases}
\frac{1}{1600} z + \frac{1}{40}, & \text{if}\quad -40 \le z \le 0 \\
-\frac{1}{1600} z + \frac{1}{40}, & \text{if}\quad 0 \le z \le 40 \\
0, & \text{otherwise}
\end{cases}
$$

Best Answer

First calculate the joint density $(X,Y)$ that is

$$f_{XY}(x,y)=\frac{1}{2x}\cdot\frac{x}{800}=\frac{1}{1600}\cdot\mathbb{1}_{[0;40]}(x)\cdot\mathbb{1}_{[0;2x]}(y)$$

Now there are several different ways to solve the problem.

  1. using the definition of CDF thus settin $Z=Y-X$ you get

$$F_Z(z)=\mathbb{P}[Y-X\leq z]=\mathbb{P}[Y\leq z+X]$$

... lot of calculations because you have to get the integral of $f(x,y)$ under the line $Y=z+X$ inside the triangular area of the joint support of $(X,Y)$ in order to get $F_Z$ than derivating it you get the desired $f_Z(z)$

Sketch of the integral regions

enter image description here

  1. (Suggested procedure) : Using Convolution

Set the following system

$$ \begin{cases} z=y-x \\ u=x \end{cases}\rightarrow\begin{cases} x=u \\ y=z+u \end{cases}$$

the jacobian is evidently $|J|=1$ thus the joint density is

$$f_{UZ}(u,z)=\frac{1}{1600}$$

The remaining difficulty is now only to realize where is the joint support of $(U,Z)$ but it is easy to discover it observing that

$$0<z+u<2u$$

that is also

$$-u<z<u$$

Concluding:

$$f_{UZ}(u,z)=\frac{1}{1600}\cdot\mathbb{1}_{[0;40]}(u)\cdot\mathbb{1}_{[-u;u]}(z)$$

In order to derive $f_Z(z)$ simply express the joint domain

enter image description here

...in a more suitable way finding

$$f_{UZ}(u,z)=\frac{1}{1600}\left[\mathbb{1}_{[-40;0]}(z)\cdot\mathbb{1}_{[-z;40]}(u)+\mathbb{1}_{[0;40]}(z)\cdot\mathbb{1}_{[z;40]}(u)\right]$$

in this way integral bounds are self evident

For $z<0$ you get

$$f_Z(z)=\frac{1}{1600}\int_{-z}^{40}du=\frac{40+z}{1600}$$

For $z>0$ you get

$$f_Z(z)=\frac{1}{1600}\int_{z}^{40}du=\frac{40-z}{1600}$$

which is exaclty the textbook's solution (a triangular density)