# Density function with absolute value

Let $X$ be a random variable distributed with the following density function:

$$f(x)=\frac{1}{2} \exp(-|x-\theta|) \>.$$

Calculate: $$F(t)=\mathbb P[X\leq t], \mathbb E[X] , \mathrm{Var}[X]$$

I have problems calculating $F(t)$ because of the absolute value. I'm doing it by case statements but it just doesn't get me to the right answer. So it gets to this: $$\int_{-\infty}^\infty\frac{1}{2} \exp(-|x-\theta|)\,\mathrm dx$$

-

The first approach we take, though correct, is not the best one, and we later describe a better approach.

Suppose first that $x \ge \theta$. By symmetry, the probability that $X\le \theta$ is $\frac{1}{2}$. So if $x\ge \theta$, then $$P(X\le x)= \frac{1}{2}+\int_{\theta}^x \frac{1}{2}e^{-(t-\theta)}\,dt.$$ The integration can be done by pulling out the $e^\theta$, but I prefer to make the substitution $u=t-\theta$. The integral becomes $$\int_{u=0}^{x+\theta} \frac{1}{2}e^{-u}du,$$ which evaluates to $$\frac{1}{2}(1-e^{-(x-\theta}).$$ Adding the $\frac{1}{2}$ for the probability that $X\le \theta$, we find that for $x\ge\theta$, $F_X(x)=1-\frac{1}{2}e^{-(x-\theta)}.$

For $x<\theta$, we need to find $$\int_{-\infty}^x \frac{1}{2}e^{t-\theta}dt.$$ The integration is straightforward. We get that $F_X(x)=\frac{1}{2}e^{x-\theta}$ whenever $x <\theta$. We could go on the find the mean and variance by similar calculations, but will now change approach.

Another approach: The $\theta$ is a nuisance. Let's get rid of it. So let $Y=X-\theta$. Then $P(Y\le y)=P(X\le y-\theta)$. This is $$\int_{-\infty}^{y-\theta} \frac{1}{2}e^{-|t-\theta|}dt.$$ Make the change of variable $w=t-\theta$. We find that our integral is $$\int_{w=-\infty}^y \frac{1}{2}e^{-|w|}dw.$$ What this shows is the intuitively obvious fact that $Y$ has a distribution of the same family as the one for $X$, except that now the parameter is $0$. We could now repeat our integration work, with less risk of error. But that would be a waste of space, so instead we go on to find the expectation of $X$.

Since $X=Y+\theta$, we have $E(X)=E(Y)+\theta$. On the assumption that this expectation exists, by symmetry $E(Y)=0$, and therefore $E(X)=\theta$.

Next we deal with $\text{Var}(X)$. Since $X=Y+\theta$, the variance of $X$ is the same as the variance of $Y$. So we need to find $$\int_{-\infty}^\infty \frac{1}{2}w^2e^{-|w|}dw.$$ By symmetry, this is twice the integral from $0$ to $\infty$, so we want $$\int_0^\infty w^2e^{-w}dw.$$ Integration by parts (twice) handles this problem. To start, let $u=w^2$, and let $dv=e^{-w}dw$. After a little while, you should find that the variance of $Y$, and hence of $X$, is $2$.

Remark: You can also find the mean and variance of $X$ by working directly with the original density function of $X$, and making an immediate substitution for $x-\theta$. But defining the new random variable $Y$ is in my view a more "probabilistic" approach.

Your distribution is a special case of the Laplace distribution, which in addition to a location parameter $\theta$, has a scale parameter $b$. The probability density function is $$\frac{1}{2b}e^{-\frac{|x-\theta|}{b}}.$$

-

The very best thing you can do in solving problems such as these is to sketch the given density function first. It does not have to be a very accurate sketch: if you drew a peak of $\frac{1}{2}$ at $x=\theta$ and decaying curves on either side, that's good enough!

Finding $F_X(t)$:

• Pick a number $t$ that is smaller than $\theta$ (where that peak is) and remember that $F_X(t)$ is just the area under the exponential curve to the left of $t$. You can find this area by integration.

• Think why it must be that $F_X(\theta) = \frac{1}{2}$.

• Pick a $t > \theta$. Once again, you have to find $F_X(t)$ which is the area under the density to the left of $t$. This is clearly the area to the left of $\theta$ (said area is $\frac{1}{2}$, of course!) plus the area under the curve between $\theta$ and $t$ which you can find by integration. Or you can be clever about it and say that the area to the right of $t = \theta + 5$ must, by symmetry, equal the area to the left of $\theta - 5$, which you found previously. Since the total area is $1$, we have $F_X(\theta+5)=1-F_X(\theta-5)$, or more generally, $$F_X(\theta + \alpha) = 1 - F_X(\theta - \alpha).$$

Finding $E[X]$:

Since the pdf is symmetric about $\theta$, it should work out that $E[X]=\theta$ but we do need to check that the integral does not work out to be of the undefined form $\infty-\infty$.

-

If $x\ge\theta$ then $|x-\theta|=x-\theta$.

If $x<\theta$ then $|x-\theta| = \theta-x$.

So $$\int_{-\infty}^\infty x \frac 1 2 \exp(-|x-\theta|)\,dx = \int_{-\infty}^\theta x\frac 1 2 \exp(\theta-x)\;dx + \frac 1 2 \int_\theta^\infty x \exp(\theta-x)\;dx.$$

By symmetry, the expected value should be $\theta$ if there is an expected value at all. And, as it happens, there is. The only thing that would prevent that is if one of the integrals were $+\infty$ and the other $-\infty$.

If you use the substitution $$u = x-\theta, \qquad du = dx,$$ then what you have above becomes $$\frac 1 2 \int_{-\infty}^0 (u+\theta) \exp(u)\;du + \frac 1 2\int_0^\infty (u+\theta)\exp(-u)\;du$$ This is \begin{align} & \frac 1 2 \int_{-\infty}^0 u \exp(u)\;du + \frac 1 2 \int_0^\infty u\exp(-u)\;du + \frac 1 2 \int_{-\infty}^0 \theta \exp(u)\;du + \frac 1 2 \int_0^\infty \theta\exp(-u)\;du \\ \\ & = \frac 1 2 \int_{-\infty}^\infty u \exp(-|u|)\;du + \theta\int_{-\infty}^\infty \frac 1 2 \exp(-|u|)\;du \end{align} The first integral on the last line is $0$ because you're integrating an odd function over the whole line. The second is $1$ because you're integrating a probability density function over the whole line.

So you're left with $\theta$.

-
There are some typos in the last few lines. In particular, $\int_{-\infty}^\infty u \exp(|u|) du$ is of the form $\infty-\infty$ and not $0$. Also, $\exp(-|u|)$ is two times a density function and its integral is $2$. – Dilip Sarwate Feb 20 '12 at 19:36
Yeah Dilip, I know it goes from negative infinite to infinite but I didn't know how to put it that way, now I know, Thanks! – Arturo Villarreal Portillo Feb 21 '12 at 1:21
Typos fixed (unless I missed some). – Michael Hardy Feb 21 '12 at 17:06
Michael, that first integral on the last line is precisely where you should not be saying the value is $0$ because you're integrating an odd function over the whole line. That is the place where you want to make sure that you are not getting $\infty-\infty = 0$ as you stressed earlier in your answer. Better to say that the first two integrals on the previous line have value $-1$ and $+1$ respectively via in integration by parts or by relating them to $\Gamma(2)$ so that the last line has only the second integral. – Dilip Sarwate Feb 21 '12 at 17:50