# Finding $E[|X-\mu|]$ dealing with absolute integration.

I would like to find $E[|X-\mu|]$ when $X$ is $N(\mu, \sigma^2)$.

I think I need to evaluate the integral:

$$E[|X-\mu|]=\int_{\mathbb{R}} |x-\mu| \frac{1}{\sigma\sqrt{2 \pi}} e^{-\frac{1}{2} \left( \frac{x-\mu}{\sigma} \right)^2} dx$$

This is the same as the following since $e^u>0$

$$=\int_{\mathbb{R}} \left|(x-\mu) \frac{1}{\sigma\sqrt{2 \pi}}e^{-\frac{1}{2} \left( \frac{x-\mu}{\sigma} \right)^2}\right| \, dx$$

So, I need to find the solution to:

$$(x-\mu) \frac{1}{\sigma\sqrt{2 \pi}}e^{-\frac{1}{2}\left( \frac{x-\mu}{\sigma} \right)^2}=0$$

To determine where to break the integral. The above is only zero where $x=\mu$. So I break it at $\mu$

$$E[|X-\mu|]=\int_{-\infty}^\mu \left|(x-\mu) \frac{1}{\sigma\sqrt{2 \pi}} e^{-\frac{1}{2} \left( \frac{x-\mu}{\sigma} \right)^2}\right| \, dx + \int_\mu^\infty \left|(x-\mu) \frac{1}{\sigma\sqrt{2 \pi}}e^{-\frac{1}{2}\left( \frac{x-\mu}{\sigma} \right)^2}\right| \, dx$$

If $x \in (-\infty, \mu)$ then $x-\mu<0$ so we can multiply the first integral by $-1$ and remove the absolute value bars.

$$E[|X-\mu|]=-\int_{-\infty}^\mu (x-\mu) \frac{1}{\sigma\sqrt{2 \pi}} e^{-\frac{1}{2} \left( \frac{x-\mu}{\sigma} \right)^2} \, dx + \int_\mu^\infty (x-\mu) \frac{1}{\sigma\sqrt{2 \pi}}e^{-\frac{1}{2}\left( \frac{x-\mu} \sigma \right)^2} \, dx$$

now we have:

$$=-\int_{-\infty}^{\mu} \frac{1}{\sigma\sqrt{2 \pi}}xe^{-\frac{1}{2}\left( \frac{x-\mu}{\sigma} \right)^2}dx +\mu\int_{-\infty}^{\mu} \frac{1}{\sigma\sqrt{2 \pi}}e^{-\frac{1}{2}\left( \frac{x-\mu}{\sigma} \right)^2}dx +{}$$

$$\int_\mu^\infty \frac{1}{\sigma\sqrt{2 \pi}}xe^{-\frac{1}{2}\left( \frac{x-\mu}{\sigma} \right)^2} \, dx -\mu\int_\mu^\infty \frac{1}{\sigma\sqrt{2 \pi}}e^{-\frac{1}{2}\left( \frac{x-\mu}{\sigma} \right)^2} \, dx$$

I'm not certain how to deal with these integrals? Any hints?

• What is the expectation of $X-\mu$ ? Jun 30, 2017 at 23:53
• Isn't $E[X-\mu]=0$? Jun 30, 2017 at 23:55
• Yes, and I was hoping to nudge you to beating Michael Hardy to the punch. Jul 1, 2017 at 0:15

$X-\mu\sim N(0,\sigma^2)$. thus $E(|X-\mu|)=\int_R|x|\frac{1}{\sqrt{2\pi}\sigma}e^{-x^2/2\sigma^2}dx=2\int^\infty_0 x\frac{1}{\sqrt{2\pi}\sigma}e^{-x^2/2\sigma^2}dx$. The antiderivative is $\frac{-2\sigma^2}{\sqrt{2\pi}}e^{-x^2/2\sigma^2}$. Thus the answer is $2\sigma^2/\sqrt{2\pi}$

You omitted some simplifications. In the first place if $X\sim N(\mu,\sigma^2)$ we can let $Y= X-\mu$ so that $Y\sim N(0,\sigma^2)$ and then we have $\operatorname{E}|X-\mu| = \operatorname{E}|Y|.$

Next, if we let $Z= Y/\sigma$ then we have $Z\sim N(0,1)$ and $\operatorname{E}|Y| = \sigma\operatorname{E}|Z|.$

So the number you seek is $\sigma\operatorname{E}|Z|.$

Next you have \begin{align} \operatorname{E}|Z| = {} & \frac 1 {\sqrt{2\pi}} \int_{-\infty}^\infty |z| e^{-z^2/2} \, dz = \frac 2 {\sqrt{2\pi}} \int_0^\infty z e^{-z^2/2} \,dz \\ & \qquad \text{because we are integrating an even function} \\ & \qquad \text{over a set that is symmetric about 0} \\[15pt] = {} & \frac 2 {\sqrt{2\pi}} \int_0^\infty e^{-z^2/2} \Big( z\, dz\Big) = \frac 2 {\sqrt{2\pi}} \int_0^\infty e^{-u} \, du = \frac 2 {\sqrt{2\pi}}\cdot 1. \\ & \qquad \text{(Note that as $z$ goes from $0$ to $\infty$, so does $u$, so the} \\ & \qquad \phantom{\text{(}} \text{bounds in this last integral are from $0$ to $\infty$.)} \end{align}

$\left(\text{And if you like you can write } \dfrac 2 {\sqrt{2\pi}} = \sqrt{\dfrac 2 \pi}. \right)$

• I feel like you have sigma =1 in that solution. Jul 1, 2017 at 0:09
• @futurebird : I have $\operatorname{E}|Z| = \dfrac 1 {\sqrt{2\pi}},$ and I said the answer you seek is $\sigma\operatorname{E}|Z|. \qquad$ Jul 1, 2017 at 0:12
• Thanks it makes more sense now. Jul 1, 2017 at 2:53