# Difference of Exponential Random Variables / Linear Transformations of RVs

Suppose X and Y are both distributed exponentially with parameter $\lambda$ and $\mu$ respectively. I am trying to find the distribution of X - Y via this method and it does not seem to be working, could you show me what I am doing wrong?

Define Z1 = X - Y, Z2 = Y so $\begin{bmatrix} Z1 \\ Z2 \end{bmatrix}$ = $\begin{bmatrix} 1 & -1 \\ 0 & 1 \end{bmatrix}$ $\begin{bmatrix} X \\ Y \end{bmatrix}$ and so $\begin{bmatrix} X \\ Y \end{bmatrix}$ = $\begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}$ $\begin{bmatrix} Z1 \\ Z2 \end{bmatrix}$

So the joint pdf of Z1 and Z2 is $g(z_1, z_2) = 1/det A * f_X(z_1 + z_2)f_Y(z2) = \lambda e^{-\lambda(z_1+z_2)} \mu e^{-\mu z_2} =\lambda \mu e^{-(\lambda + \mu)z_2 -\lambda z_1}$.

Hence the marginal density of Z1 is $g(z_1) = \int_0^\infty \lambda \mu e^{-(\lambda + \mu)z_2 -\lambda z_1} dz_2 = [ \frac{-\lambda \mu}{\lambda + \mu} e^{-(\lambda + \mu)z_2 - \lambda z_1}]^{\infty}_0 = \frac{\lambda \mu}{\lambda + \mu} e^{-\lambda z_1}$ Which is wrong?

You have the correct joint density function for $Z_1,Z_2$:

$$f_{Z_1,Z_2}(z_1,z_2) = \lambda\mu e^{-(\lambda + \mu)z_2-\lambda z_1}.$$

However, the ranges $X\gt 0,\;Y\gt 0$ imply the ranges for $Z_1,Z_2$ are:

$$Z_2 \gt 0,\quad Z_2 \gt -Z_1.$$

So to calculate the marginal density for $Z_1$ we must work with two ranges:

If $z_1 \geq 0$ then we proceed exactly as you have done, giving

$$f_{Z_1}(z_1) = \dfrac{\lambda\mu}{\lambda + \mu}e^{-\lambda z_1}.$$

If $z_1 \lt 0$ then:

\begin{eqnarray*} f_{Z_1}(z_1) &=& \int_{-z_1}^\infty{\lambda\mu e^{-(\lambda + \mu)z_2-\lambda z_1}\;dz_2} \\ &=& \left[\dfrac{-\lambda\mu}{\lambda + \mu} e^{-(\lambda + \mu)z_2-\lambda z_1}\right]_{-z_1}^\infty \\ &=& \dfrac{\lambda\mu}{\lambda + \mu}e^{\mu z_1}. \end{eqnarray*}

• Then why does this answer (math.stackexchange.com/questions/115022/…) indicate it should be $g(z_1)=\frac{\lambda \mu}{\lambda + \mu} e^{-\mu z_1}$ for z >= 0, also with my answer we get $P(X > Y) = P(Z_1 > 0) = \int_0^\infty f_{Z_1}(z_1) = \dfrac{\lambda\mu}{\lambda + \mu}e^{-\lambda z_1} dz_1 = \frac{\mu}{\lambda + \mu}$ whereas it should be $\frac{\lambda}{\lambda + \mu}$? – dakenSoren Apr 5 '15 at 15:06
• @dakenSoren Hi Daken. Your question has the $\lambda$ and $\mu$ the other way round compared to that other question. Considering that, I think my answer matches Robert Israel's answer. (I didn't know this question has already been asked and answered.) – Mick A Apr 5 '15 at 15:16
• I forgot to say thanks for the answer. I see, at that previous link I looked at Andre's answer and I thought that I ruled out that possibility as he states : "The density function of $X$ is $\lambda e^{-\lambda x}$", however he also defines $Z=Y-X$ whereas I have $Z=X-Y$, so it was the double switch that caught me out. Thank you for your help, also the question was to see why my particular method did not work, so it was not really duplication. – dakenSoren Apr 5 '15 at 15:57
• @dakenSoren No problem. Glad to help. :-) – Mick A Apr 5 '15 at 16:07