Why two equivalent method for computation of the expected value of a Gaussian distribution produces two different results

49 Views Asked by At

I have the following question about a random simulation that I am doing.

I want to compute \begin{align} M_1=E[|Z|] + E[|Z+a|] \end{align} where $a$ is some fixed constant and $Z$ is a standard normal.

Next, observe that

\begin{align} E[|Z+a|]&= \int |z+a| \frac{1}{\sqrt{2\pi}}\exp(-z^2/2) dz \\ &= \int |z| \frac{1}{\sqrt{2\pi}}\exp(-(z-a)^2/2) dz \\ &= \int |z| \exp( az -a^2/2) \frac{1}{\sqrt{2\pi}}\exp(-z^2/2) dz \\ &= E \left[|Z| \exp( aZ -a^2/2)\right] \end{align} Therefore, \begin{align} E[|Z|] + E[|Z+a|] &= E[|Z|] + E \left[|Z| \exp( aZ -a^2/2)\right]\\ &=E \left[|Z| \left(1+\exp( aZ -a^2/2) \right)\right]\\ &=M_2 \end{align}

I don't see a mistake in the above steps and I think $M_1=M_2$.

However, if I do a numerical simulation for example for a value of $a=3$ I get different values for $M_1$ and $M_2$. How can this be? Clearly, I am making a mistake somewhere. However, I am not sure where?

Here is the MatLab code that I am using

a=3;

Z=randn(1,2000);

M1=mean( abs(Z))+ mean( abs(Z+a))

M2= mean(abs(Z).*(1+exp( a*Z-a^2/2)))

and the outputs are

M1 =

3.7768

M3 =

0.8341
2

There are 2 best solutions below

1
On BEST ANSWER

2000 is not enough to sample from the second one. I did 5 million and have consistently observed values close to M1. (The reason there is simply the second way egregiously shifts values around because of that exponential term; it is like both the random variable that is 0 and 2 with probability 1/2 each, and a random variable that takes 1000000 with probability 1/1000000 both have mean 1, but if you don't sample enough, you will not be able to see the difference.)

0
On

Your calculation is correct and the expressions $M_1$ and $M_2$ are indeed equivalent; furthermore, they are both equal to $$\operatorname{E}[|Z|] + \operatorname{E}[|Z-a|] = \sqrt{\frac{2}{\pi}} \left( 1 + e^{-a^2/2} \right) + (2 \Phi(a) - 1)a,$$ where $\Phi(z) = \Pr[Z \le z]$ is the CDF of the standard normal distribution.