Suppose we have two independent random variables $Y$ and $X$, both being exponentially distributed with respective parameters $\mu$ and $\lambda$.

How can we calculate the pdf of $Y-X$?


4 Answers 4


You can think of $X$ and $Y$ as waiting times for two independent things (say $A$ and $B$ respectively) to happen. Suppose we wait until the first of these happens. If it is $A$, then (by the lack-of-memory property of the exponential distribution) the further waiting time until $B$ happens still has the same exponential distribution as $Y$; if it is $B$, the further waiting time until $A$ happens still has the same exponential distribution as $X$. That says that the conditional distribution of $Y-X$ given $Y > X$ is the distribution of $Y$, and the conditional distribution of $Y-X$ given $Y < X$ is the distribution of $-X$.

Let $Z=Y-X$. We use a formula related to the law of total probability: $$f_Z(x) = f_{Z|Z<0}(x)P(Z<0) + f_{Z|Z\geq 0}(x)P(Z\geq 0)\,.$$

Given that we know $P(Z<0)= P(Y<X) = \frac{\mu}{\mu+\lambda}$, and correspondingly $P(Y>X) = \frac{\lambda}{\mu+\lambda}$, the above implies that the pdf for $Y-X$ is $$ f(x) = \frac{\lambda \mu}{\lambda+\mu} \cases{e^{\lambda x} & if $x < 0 $\cr e^{-\mu x} & if $x \geq 0 \,.$\cr}$$

  • 12
    $\begingroup$ why $P(X>Y)=\frac{\lambda}{\mu+\lambda}$? $\endgroup$
    – user65985
    Aug 14, 2013 at 16:55
  • 5
    $\begingroup$ $X$ ~ $Exp(\mu)$ and $Y$ ~ $Exp(\lambda)$ then: $P(Y < X) = \int_0^\infty\int_0^x\mu e^{-\mu y}\lambda e^{-\lambda x}dydx$ $\endgroup$ Nov 5, 2015 at 5:50
  • 3
    $\begingroup$ @YellowPillow Doesn't that give ${\mu \over \mu + \lambda}$? $\endgroup$
    – Columbo
    Apr 13, 2016 at 14:59
  • $\begingroup$ This can also be found by the convolution between two pdfs $\endgroup$
    – makansij
    Apr 28, 2016 at 4:42
  • $\begingroup$ Isnt this (kind of) symmetrization? $\endgroup$
    – user515599
    Dec 20, 2019 at 10:35

The right answer depends very much on what your mathematical background is. I will assume that you have seen some calculus of several variables, and not much beyond that. Instead of using your $u$ and $v$, I will use $X$ and $Y$.

The density function of $X$ is $\lambda e^{-\lambda x}$ (for $x \ge 0$), and $0$ elsewhere. There is a similar expression for the density function of $Y$. By independence, the joint density function of $X$ and $Y$ is $$\lambda\mu e^{-\lambda x}e^{-\mu y}$$ in the first quadrant, and $0$ elsewhere.

Let $Z=Y-X$. We want to find the density function of $Z$. First we will find the cumulative distribution function $F_Z(z)$ of $Z$, that is, the probability that $Z\le z$.

So we want the probability that $Y-X \le z$. The geometry is a little different when $z$ is positive than when $z$ is negative. I will do $z$ positive, and you can take care of negative $z$.

Consider $z$ fixed and positive, and draw the line $y-x=z$. We want to find the probability that the ordered pair $(X,Y)$ ends up below that line or on it. The only relevant region is in the first quadrant. So let $D$ be the part of the first quadrant that lies below or on the line $y=x+z$. Then $$P(Z \le z)=\iint_D \lambda\mu e^{-\lambda x}e^{-\mu y}\,dx\,dy.$$

We will evaluate this integral, by using an iterated integral. First we will integrate with respect to $y$, and then with respect to $x$. Note that $y$ travels from $0$ to $x+z$, and then $x$ travels from $0$ to infinity. Thus $$P(Z\le x)=\int_0^\infty \lambda e^{-\lambda x}\left(\int_{y=0}^{x+z} \mu e^{-\mu y}\,dy\right)dx.$$

The inner integral turns out to be $1-e^{-\mu(x+z)}$. So now we need to find $$\int_0^\infty \left(\lambda e^{-\lambda x}-\lambda e^{-\mu z} e^{-(\lambda+\mu)x}\right)dx.$$ The first part is easy, it is $1$. The second part is fairly routine. We end up with $$P(Z \le z)=1-\frac{\lambda}{\lambda+\mu}e^{-\mu z}.$$ For the density function $f_Z(z)$ of $Z$, differentiate the cumulative distribution function. We get $$f_Z(z)=\frac{\lambda\mu}{\lambda+\mu} e^{-\mu z} \quad\text{for $z \ge 0$.}$$ Please note that we only dealt with positive $z$. A very similar argument will get you $f_Z(z)$ at negative values of $z$. The main difference is that the final integration is from $x=-z$ on.

  • $\begingroup$ Before the first double integral, should that be "below or on the line $y = x + z$"? $\endgroup$
    – Patrick
    Mar 1, 2012 at 0:10
  • $\begingroup$ @Patrick: Thank you for spotting the typo! Fixed. $\endgroup$ Mar 1, 2012 at 0:23

There is an alternative way to get the result by applying the the Law of Total Probability. If $W$ and $Z$ are random variables, $$ P[W\leq w] = \int_Z P[W \leq w\mid Z = z]f_Z(z)dz $$

As others have done, let $X \sim \exp(\lambda)$ and $Y \sim \exp(\mu)$. What follows is the only slightly unintuitive step: instead of directly calculating the PDF of $Y-X$, first calculate the CDF: $ P[Y-X \leq t]$ (we can then differentiate at the end).

$$ P[Y - X \leq t] = P[Y \leq t+X] $$

This is where we'll apply total probability to get

$$ = \int_0^\infty P[Y \leq t+X \mid X=x]f_X(x) dx $$ $$ = \int_0^\infty P[Y \leq t+x]f_X(x) dx = \int_0^\infty F_Y(t+x) f_X(x) dx $$ Note substituting the CDF here is only valid if $t \geq 0$, $$ = \int_0^\infty (1- e^{-\mu(t+x)}) \lambda e^{-\lambda x} dx = \lambda \int_0^\infty e^{-\lambda x} dx - \lambda e^{-\mu t} \int_0^\infty e^{-(\lambda+\mu)x} dx $$ $$ = \lambda \left[ \frac{e^{-\lambda x}}{-\lambda} \right]^\infty_0 - \lambda e^{-\mu t} \left[ \frac{e^{-(\lambda+\mu)x}}{-(\lambda+\mu)} \right]^\infty_0 =1 - \frac{\lambda e^{-\mu t}}{\lambda+\mu} $$

Differentiating this last expression gives us the PDF:

$$ f_{Y-X}(t) = \frac{\lambda \mu e^{-\mu t}}{\lambda+\mu} \quad \text{for $t \geq 0$} $$

  • $\begingroup$ What is $W$? An event? A random variable? What is $P(W)$? $\endgroup$
    – Lorents
    Mar 20 at 14:08

The general representation for the density of the difference of independent gamma random variables $Z=X-Y$ with $X\sim\operatorname{Gamma}(\alpha_1,\lambda_1)$ and $Y\sim\operatorname{Gamma}(\alpha_2,\lambda_2)$ is given by [1] in the form $$ f_Z(z)= \begin{cases} \frac{C}{\Gamma(\alpha_2)}e^{\lambda_2z}U(1-\alpha_2,2-\alpha_1-\alpha_2,-(\lambda_1+\lambda_2)z), &z\leq 0\\ \frac{C}{\Gamma(\alpha_1)}e^{-\lambda_1z}U(1-\alpha_1,2-\alpha_1-\alpha_2,(\lambda_1+\lambda_2)z), &z>0 \end{cases} $$ where $C=\lambda_1^{\alpha_1}\lambda_2^{\alpha_2}(\lambda_1+\lambda_2)^{1-\alpha_1-\alpha_2}$ and $U(a,b,z)$ is the confluent hypergeometric function of the 2nd-kind. Substituting $\alpha_1=\alpha_2=1$ into this expression give the desired density, namely, $$ f_Z(z)= \begin{cases} \frac{\lambda_1\lambda_2}{\lambda_1+\lambda_2}e^{\lambda_2z}, &z\leq 0\\ \frac{\lambda_1\lambda_2}{\lambda_1+\lambda_2}e^{-\lambda_1z}, &z>0. \end{cases} $$

[1] Aaron Hendrickson, The inverse gamma-difference distribution and its first moment in the Cauchy principal value sense, Stat. Interface 12(2019), no. 3, 467-478, DOI 10.4310/19-SII564


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .