# pdf for a difference of exponential random variables

Suppose $X$ is an exponential random variable with mean $2$, and $Y$ is an exponential random variable with mean $3$. I want to write the density function for $X-Y$. Now, I know (at least, I'm pretty sure) that this is calculated by the formula:

$f_{X-Y}(z)=\displaystyle\int_{-\infty}^\infty f_X(y)f_Y(y-z)\,dy$,

but I have a hard time with the actual calculation. The trouble is that both $f_X$ and $f_Y$ have support $[0,\infty)$, and that makes me confused about when the expression $f_Y(y-z)$ is defined.

To be clear, I have the density functions:

$f_X(y)=\frac12e^{-y/2}$, $f_Y(y)=\frac13e^{-y/3}$, both for $y\ge 0$.

I hope my question makes sense; thanks in advance.

• Yes, the integrals can be simplified to consider only $y \geq 0$ (so that $f_X(y) >0$) and $y - z \geq 0$ (so that $f_Y(y-z)>0$). Since $z$ is a constant and $y$ is the integration variable, it means $\int_{y= \max[0,z]}^{\infty}$. – Michael Dec 19 '16 at 3:07
• So if we assume $z\geq 0$, then $y$ takes values of all real numbers greater than or equal to $z$. Remember that, with respect to the integral, $z$ is a constant and does not change, while $y$ is the integration variable. – Michael Dec 19 '16 at 3:10
• The difference of two independent exponentials is a Laplace distribution. Have a look at en.wikipedia.org/wiki/… – A.G. Dec 19 '16 at 3:11
• It looks like this question has come up previously, math.stackexchange.com/questions/115022/… – jjet Dec 19 '16 at 3:12
• @A.G. Only the weighted difference has Laplace distribution. – msm Dec 19 '16 at 5:11

We are convolving $X\sim f_X(x)={\frac{1}{2}e^{-x/2}}$ supported on ${[0,\infty)}$ with $-Y\sim f_{-Y}(y)={\frac{1}{3}e^{y/3}}$ supported on ${(-\infty,0]}$. Now consider the graphical representations for convolution of these two exponential functions. We fix the former and move the mirrored of the latter with respect to the $y$-axis: $$f_Z(z)=\int_{-\infty}^{\infty}\color{blue}{f_X(\tau)}\color{red}{f_{-Y}(-\tau+z)}d\tau$$

When $z<0$: \begin{align} f_Z(z)&=\int_0^\infty\frac{1}{2}e^{-\tau/2}.\frac{1}{3}e^{(z-\tau)/3}\mathrm d\tau\\ &=\frac{e^{z/3}}{6}\int_0^\infty e^{-5\tau/6}\mathrm d\tau\\ &=\frac{e^{z/3}}{6}\left(\frac{-6}{5}\right)(0-1)\\ &=\frac{1}{5}e^{z/3} \end{align}

When $z>0$: \begin{align} f_Z(z)&=\int_z^\infty\frac{1}{2}e^{-\tau/2}.\frac{1}{3}e^{(z-\tau)/3}\mathrm d\tau\\ &=\frac{e^{z/3}}{6}\int_z^\infty\frac{1}{6}e^{-5\tau/6}\mathrm d\tau\\ &=\frac{e^{z/3}}{6}\left(\frac{-6}{5}\right)(0-e^{-5z/6})\\ &=\frac{1}{5}e^{-z/2} \end{align}

• The pictures are really helpful! I've never seen convolution depicted graphically before; that really clarifies the domains. – G Tony Jacobs Dec 19 '16 at 22:22
• More intuitive illustration of convolution [of two other functions]. – msm Dec 19 '16 at 22:48

To get the formula for $f_Z$ consider \begin{align} \mathbb{P}(X-Y<z)& =\iint _{x-y<z} f(x,y)\mathrm{d}x\mathrm{d}y \\ &= \frac 16 \iint_{x < z+y} e^{-y/3}e^{-x/2}\mathrm{d}x\mathrm{d}y \end{align} Now, to find the region of integration, we know that $0<x<\infty$ and $0<y<\infty$, from the above we also know that $0<x<z+y$, and therefore $\max (-z,0) <y < \infty$. From here we get two cases $$0<y \quad \mathrm{and} \quad 0<z$$ $$-z<y \quad \mathrm{and} \quad z<0$$ $$\mathbb{P}(X-Y<z)=\frac 16 \int_0^{\infty}\int_0^{z+y} e^{-y/3}e^{-x/2}\mathrm{d}x\mathrm{d}y$$ For positive $z$ and $$\mathbb{P}(X-Y<z)=\frac 16 \int_{-z}^{\infty}\int_0^{z+y}e^{-y/3}e^{-x/2}\mathrm{d}x\mathrm{d}y$$ For negative $z$. These integrals give $$1-\frac 25 e^{-z/2}$$ and $$\frac 35 e^{z/3}$$ Respectively, differentiate to get the PDF $$f_Z(z) = \frac 15 \cases{e^{-z/2} & if z > 0\cr e^{ z/3} & if z < 0\cr}$$

In the general case, suppose $X$ and $Y$ are independent exponentially distributed random variables with rate parameters $a$ and $b$; thus $$f_X(x) = a e^{-ax} \mathbb 1(x > 0), \quad F_X(x) = (1 - e^{-ax})\mathbb 1(x > 0), \\ f_Y(y) = b e^{-by} \mathbb 1(y > 0), \quad F_Y(y) = (1 - e^{-by})\mathbb 1 (y > 0).$$ Then the CDF of $Z = X - Y$ is \begin{align*} F_Z(z) &= \Pr[X - Y \le z] \\ &= \int_{y=-\infty}^\infty \Pr[X \le z + y] f_Y(y) \, dy \\ &= \int_{y=-\infty}^\infty (1 - e^{-a(z+y)}) be^{-by} \mathbb 1 (z+y > 0) \mathbb 1 (y > 0) \, dy \\ &= \int_{y = \max(0,-z)}^\infty be^{-by} - e^{-az} be^{-(a+b)y} \, dy \\ &= \left[-e^{-by} + \frac{b e^{-az} e^{-(a+b)y}}{a+b}\right]_{y=\max(0,-z)}^\infty \\ &= \left(\frac{e^{a\max(0,-z)}}{b} - \frac{e^{-az}}{a+b}\right) b e^{-(a+b) \max(0,-z)}. \end{align*} When $z < 0$, $\max(0,-z) = z$, and we get $$F_Z(z) = \frac{ae^{bz}}{a+b}.$$ When $z \ge 0$, $\max(0,-z) = 0$ and we get $$F_Z(z) = 1 - \frac{be^{-az}}{a+b}.$$ Therefore, the CDF can be written piecewise as $$F_Z(z) = \begin{cases} \frac{ae^{bz}}{a+b}, & z < 0 \\ 1 - \frac{be^{-az}}{a+b}, & z \ge 0.\end{cases},$$ with the PDF $$f_Z(z) = F'_Z(z) = \frac{ab}{a+b} \begin{cases} e^{bz}, & z < 0 \\ e^{-az}, & z \ge 0. \end{cases}.$$