# How can I derive the variance of the half-normal distribution?

Let $$X$$ follow a half-normal distribution with pdf $$f(x|\sigma)=\frac{\sqrt{2}}{\sigma\sqrt{\pi}}exp(-\frac{x^2}{2\sigma^2}), x >0$$. How can I derive $$Var(X)$$?

my work:

I know that $$Var(X)=E(X^2)-(EX)^2$$, but I cannot solve for $$E(X^2)$$:

$$E(X^2)=\int^\infty_0\frac{\sqrt{2}x^2}{\sigma\sqrt{\pi}}exp(-\frac{x^2}{2\sigma^2})dx$$.

How can I integrate this?

• Hint: write the integral for $E[X^2]$ as a integral over the entire real line instead of an integral over the positive real line. Still stumped? Make a change of variables $y=-x$ in the integral for $E[X^2]$ to see if inspiration strikes. Apr 18, 2020 at 0:27
• @DilipSarwate I'm afraid I'm still stumped even using that change in variable. Apr 18, 2020 at 3:07
• As others have mentioned, it is as simple as $E[X^2]=E[Y^2]$ where $Y\sim N(0,\sigma^2)$. A bit more work is required for $E[X]=E[|Y|]$ but chances are this has been done here before. Apr 18, 2020 at 6:42
• Change of variable $y=x^2$ and identify a Gamma integral. Apr 18, 2020 at 7:19
• @Xi'an I like your suggested change in variable. Thanks! Apr 18, 2020 at 19:48

Hint: if $$X \sim \text{HalfNormal}(\sigma^2)$$ and $$Y \sim \text{Normal}(0,\sigma^2)$$, then for any symmetric and integrable $$f$$ $$E[f(X)] = E[f(|Y|)] = E[f(Y)|Y \ge 0] = 2 E[f(Y) 1(Y \ge 0)].$$

I always get tripped up a little on the difference between conditioning and multiplying by indicators.

• Ah, I see. That's clever. I would've messed up on including the 2 Apr 18, 2020 at 3:08

See Wikipedia on half normal. Then consider the simulation in R below. You already have some of the key results.

set.seed(2020)     # for reproducibility
z = rnorm(10^7)    # standard normal
mean(z);  mean(z^2)
 -2.9034e-06    # aprx E(Z) = 0
 0.9996958      # aprx E(Z^2) = 1
x = abs(z)
var(x);  mean(x^2);  mean(x)
 0.3633301      # aprx Var(X)= 1-2/pi = 0.363
 0.9996958      # aprx E(x^2)=E(Z^2)=1
 0.7977253      # aprx E(x)=sqrt(2/pi) = 0.798
sqrt(2/pi)
 0.7978846
1- 2/pi
 0.3633802
mean(x^2) - mean(x)^2
 0.3633301      # aprx Var(X) again


In Comment, @Dilip was trying to get you to see that $$E(Z^2) = E(X^2).$$

• Wonderful- thank you for providing the code to simulate, too! Apr 18, 2020 at 3:07