Half-normal distribution (source code)

= Half-normal distribution
{title2=$H=|Z|$}
{wiki}

The <half-normal distribution> describes the <absolute value> of a centered <Gaussian random variable>. Its unit-scale version is $H=|Z|$ for a <standard normal random variable> $Z$. It folds the negative half of the <standard normal distribution> onto the positive half, retaining the size of a deviation while discarding its sign. If a centered <Gaussian random variable> models <measurement error>, its magnitude therefore has a <half-normal distribution>.
$$
f_H(x)=\begin{cases}2\phi(x)=\sqrt{\dfrac2\pi}e^{-x^2/2},&x\geq0,\\0,&x<0,\end{cases}
\qquad
F_H(x)=\begin{cases}2\Phi(x)-1,&x\geq0,\\0,&x<0.\end{cases}
$$
Here $\phi$ is the <standard normal density> and $\Phi$ is the <standard normal distribution function>. For $x\geq0$, the <event> $H\leq x$ is $-x\leq Z\leq x$, so the <symmetric probability distribution> of $Z$ gives $F_H(x)=\Phi(x)-\Phi(-x)=2\Phi(x)-1$. The upper-tail <probability> is therefore $\mathbb P(H>x)=2(1-\Phi(x))$. For example, $\mathbb P(H\leq1)\approx0.6826894921$. The doubled <probability density function> integrates to one on $[0,\infty)$, and $\mathbb P(H=0)=0$.

The <mean> and <variance> of the unit-scale <half-normal distribution> are
$$
\mathbb E[H]=\sqrt{\frac2\pi},\qquad\operatorname{Var}(H)=1-\frac2\pi.
$$
For a short derivation, $\mathbb E[H]=2\int_0^\infty x\phi(x)\,dx=2\phi(0)$ because $\phi'(x)=-x\phi(x)$, while $H^2=Z^2$ gives $\mathbb E[H^2]=1$. More generally, $\sigma|Z|$ for $\sigma>0$ has a <half-normal distribution> with <probability density function> $2\phi(x/\sigma)/\sigma$ for $x\geq0$. Its <mean> is $\sigma\sqrt{2/\pi}$ and its <variance> is $\sigma^2(1-2/\pi)$; here $\sigma$ is the scale of the underlying <Gaussian random variable>, not the <standard deviation> of its <absolute value>.