19
$\begingroup$

I would like to learn how to calculate the expected value of a continuous random variable. It appears that the expected value is $$E[X] = \int_{-\infty}^{\infty} xf(x)\mathrm{d}x$$ where $f(x)$ is the probability density function of $X$.

Suppose the probability density function of $X$ is $$f(x) = \frac{1}{\sqrt{2\pi}}e^{\frac{-x^{2}}{2}}$$ which is the density of the standard normal distribution.

So, I would first plug in the PDF and get $$E[X] = \int_{-\infty}^{\infty} x\frac{1}{\sqrt{2\pi}}e^{\frac{-x^{2}}{2}}\mathrm{d}x$$ which is a rather messy looking equation. The constant $\displaystyle\frac{1}{\sqrt{2\pi}}$ can be moved outside the integral, giving $$E[X] = \frac{1}{\sqrt{2\pi}}\int_{-\infty}^{\infty} xe^{\frac{-x^{2}}{2}}\mathrm{d}x.$$

I get stuck here. How do I calculate integral? Am I doing this correctly this far? Is the simplest way to get the expected value?

$\endgroup$
1
  • 4
    $\begingroup$ "I get stuck here. How do I calculate integral?" Find the derivative of $-e^{-\frac{x^2}{2}}$. (No, I am not being facetious and suggesting needless busywork to you; I am deadly serious; Just Do It!). Then stare very hard at the derivative you have found. $\endgroup$ Dec 3, 2015 at 5:19

3 Answers 3

15
$\begingroup$

You are almost there, follow your last step:

$$E[X] = \frac{1}{\sqrt{2\pi}}\int_{-\infty}^{\infty} xe^{\displaystyle\frac{-x^{2}}{2}}\mathrm{d}x\\=-\frac{1}{\sqrt{2\pi}}\int_{-\infty}^{\infty}e^{-x^2/2}d(-\frac{x^2}{2})\\=-\frac{1}{\sqrt{2\pi}}e^{-x^2/2}\mid_{-\infty}^{\infty}\\=0$$.

Or you can directly use the fact that $xe^{-x^2/2}$ is an odd function and the limits of the integral are symmetric about $x=0$.

$\endgroup$
8
  • 5
    $\begingroup$ The symmetry argument only works if both halves are themselves convergent. $\endgroup$
    – Glen_b
    Oct 13, 2015 at 10:50
  • 1
    $\begingroup$ Could you explain what happens on the second row? $\endgroup$
    – mmh
    Oct 13, 2015 at 11:12
  • $\begingroup$ Glen's comment is correct if it is not convergent then change-of-variables will not work $\endgroup$
    – Deep North
    Oct 13, 2015 at 11:23
  • 1
    $\begingroup$ The second row is equal to the first row since $d(-\frac{x^2}{2})=-xdx$ also note the negative sign at the beginning. Then you can think of change of variable for integration, then you change it back since the limits did not change. Or you can use integrate by parts. And remember $\int_{a}^{b}e^y dy=e^y\mid_{a}^{b}$ $\endgroup$
    – Deep North
    Oct 13, 2015 at 11:37
  • 1
    $\begingroup$ To use symmetry to get the mean you need to know that $\int_0^\infty xf(x) dx$ converges - it does for this case, but more generally you can't assume it. For example, the symmetry argument would say that the mean of the standard Cauchy is 0, but it doesn't have one. $\endgroup$
    – Glen_b
    Dec 3, 2015 at 1:23
14
$\begingroup$

Since you want to learn methods for computing expectations, and you wish to know some simple ways, you will enjoy using the moment generating function (mgf)

$$\phi(t) = E[e^{tX}].$$

The method works especially well when the distribution function or its density are given as exponentials themselves. In this case, you don't actually have to do any integration after you observe

$$t^2/2 -\left(x - t\right)^2/2 = t^2/2 + (-x^2/2 + tx - t^2/2) = -x^2/2 + tx,$$

because, writing the standard normal density function at $x$ as $C e^{-x^2/2}$ (for a constant $C$ whose value you will not need to know), this permits you to rewrite its mgf as

$$\phi(t) = C\int_\mathbb{R} e^{tx} e^{-x^2/2} dx = C\int_\mathbb{R} e^{-x^2/2 + tx} dx = e^{t^2/2}C\int_\mathbb{R} e^{-(x-t)^2/2} dx .$$

On the right hand side, following the $e^{t^2/2}$ term, you will recognize the integral of the total probability of a Normal distribution with mean $t$ and unit variance, which therefore is $1$. Consequently

$$\phi(t) = e^{t^2/2}.$$

Because the Normal density gets small at large values so rapidly, there are no convergence issues regardless of the value of $t$. $\phi$ is recognizably analytic at $0$, meaning it equals its MacLaurin series

$$\phi(t) = e^{t^2/2} = 1 + (t^2/2) + \frac{1}{2} \left(t^2/2\right)^2 + \cdots + \frac{1}{k!}\left(t^2/2\right)^k + \cdots.$$

However, since $e^{tX}$ converges absolutely for all values of $tX$, we also may write

$$E[e^{tX}] = E\left[1 + tX + \frac{1}{2}(tX)^2 + \cdots + \frac{1}{n!}(tX)^n + \cdots\right] \\ = 1 + E[X]t + \frac{1}{2}E[X^2]t^2 + \cdots + \frac{1}{n!}E[X^n]t^n + \cdots.$$

Two convergent power series can be equal only if they are equal term by term, whence (comparing the terms involving $t^{2k} = t^n$)

$$\frac{1}{(2k)!}E[X^{2k}]t^{2k} = \frac{1}{k!}(t^2/2)^k = \frac{1}{2^kk!} t^{2k},$$

implying

$$E[X^{2k}] = \frac{(2k)!}{2^kk!},\ k = 0, 1, 2, \ldots$$

(and all expectations of odd powers of $X$ are zero). For practically no effort you have obtained the expectations of all positive integral powers of $X$ at once.


Variations of this technique can work just as nicely in some cases, such as $E[1/(1-tX)] = E[1 + tX + (tX)^2 + \cdots + (tX)^n + \cdots]$, provided the range of $X$ is suitably limited. The mgf (and its close relative the characteristic function $E[e^{itX}]$) are so generally useful, though, that you will find them given in tables of distributional properties, such as in the Wikipedia entry on the Normal distribution.

$\endgroup$
0
$\begingroup$

A more straightforward and general way to calculate these kinds of integrals is by changing of variable: Suppose your normal distribution has mean $\mu$ and variance $\sigma^2$: $\mathcal{N(\mu, \sigma^2)}$ $$ E(x) = \frac{1}{\sigma\sqrt{2 \pi}} \int x \exp(-\frac{(x-\mu)^2}{2\sigma^2})dx $$ now by changing the variable $y = \frac{x-\mu}{\sigma}$ and $\frac{dy}{dx}=\frac{1}{\sigma} \rightarrow dx = \sigma dy$.

$$ E(x) = \frac{\sigma}{\sigma\sqrt{2 \pi}} \int (\sigma y + \mu) \exp(-\frac{y^2}{2})dy = \\ \frac{\sigma}{\sigma\sqrt{2 \pi}} \left[ \int \sigma y e^{-\frac{y^2}{2}} dy + \mu \int e^{-\frac{y^2}{2}} dy \right] $$ The first integral is an odd integral since $y$ is an odd function and $e^{-\frac{y^2}{2}}$ is an even function which results in an odd function with symmetric integral boundaries and is zero. The second integral itself has an answer of $2\pi$. $$ E(x) = \frac{\mu \sigma \sqrt{2 \pi}}{\sigma \sqrt{2 \pi}} = \mu $$ In your case since your distribution has a mean of zero by your definition the answer is $E(x) = 0$.

$\endgroup$
2
  • $\begingroup$ Re "very easy:" some support for this claim would be welcome. I'm confident the original proposer of this question would have been completely stymied by a request to compute, say, $E[X^{100}]$ for a standard Normal variable $X.$ $\endgroup$
    – whuber
    Apr 13 at 16:53
  • $\begingroup$ You're right. I take my word back :) Thanks. $\endgroup$ Apr 13 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.