Truncated normal distribution

{{Probability distribution | name      = | type      = density | pdf_image = tnormPDF.png | pdf_caption = Probability density function for the truncated normal distribution for different sets of parameters. In all cases, a = −10 and b = 10. For the black: μ = −8, σ = 2; blue: μ = 0, σ = 2; red: μ = 9, σ = 10; orange: μ = 0, σ = 10. | cdf_image = tnormCDF.svg | cdf_caption = Cumulative distribution function for the truncated normal distribution for different sets of parameters. In all cases, a = −10 and b = 10. For the black: μ = −8, σ = 2; blue: μ = 0, σ = 2; red: μ = 9, σ = 10; orange: μ = 0, σ = 10. | notation  = $$\xi=\frac{x-\mu}{\sigma},\ \alpha=\frac{a-\mu}{\sigma},\ \beta=\frac{b-\mu}{\sigma}$$ $$Z = \Phi(\beta)-\Phi(\alpha)$$ | parameters = {{nowrap|$$\mu \in \mathbb{R}$$}} $$\sigma^2 \geq 0$$ (but see definition) $$a \in \mathbb{R}$$ — minimum value of $$x$$ $$b \in \mathbb{R}$$ — maximum value of $$x$$ ($$b > a$$) | support   = $$x \in [a, b]$$ | pdf       = $$f(x;\mu,\sigma, a,b) = \frac{\varphi(\xi)}{\sigma Z}\,$$ | cdf       = $$F(x;\mu,\sigma, a,b) = \frac{\Phi(\xi) - \Phi(\alpha)}{Z}$$ | mean      = $$\mu +  \frac{\varphi(\alpha)-\varphi(\beta)}{Z}\sigma$$ | mode      = $$\left\{\begin{array}{ll}a, & \mathrm{if}\ \mub\end{array}\right.$$ | variance  = $$\sigma^2\left[1-\frac{\beta\varphi(\beta)-\alpha\varphi(\alpha)}{Z} -\left(\frac{\varphi(\alpha)-\varphi(\beta)}{Z}\right)^2\right]$$ | median = $$\mu + \Phi^{-1}\left(\frac{\Phi(\alpha)+\Phi(\beta)}{2}\right) \sigma$$ | skewness  = | kurtosis  = | entropy   = $$\ln(\sqrt{2 \pi e} \sigma Z) + \frac{\alpha\varphi(\alpha)-\beta\varphi(\beta)}{2Z}$$ | mgf       = $$e^{\mu t + \sigma^2 t^2 / 2}  \left[ \frac{ \Phi(\beta- \sigma t) - \Phi(\alpha - \sigma t)  }{\Phi(\beta) - \Phi(\alpha) }  \right] $$ | char      = }}

In probability and statistics, the truncated normal distribution is the probability distribution derived from that of a normally distributed random variable by bounding the random variable from either below or above (or both). The truncated normal distribution has wide applications in statistics and econometrics.

Definitions
Suppose $$ X $$ has a normal distribution with mean $$\mu$$ and variance $$\sigma^2$$ and lies within the interval $$(a,b), \text{with} \; -\infty \leq a < b \leq \infty $$. Then $$X$$ conditional on $$ a < X < b $$ has a truncated normal distribution.

Its probability density function, $$f$$, for $$ a \leq x \leq b $$, is given by

$$ f(x;\mu,\sigma,a,b) = \frac{1}{\sigma}\,\frac{\varphi(\frac{x - \mu}{\sigma})}{\Phi(\frac{b - \mu}{\sigma}) - \Phi(\frac{a - \mu}{\sigma}) }$$

and by $$f=0$$ otherwise.

Here, $$\varphi(\xi)=\frac{1}{\sqrt{2 \pi}}\exp\left(-\frac{1}{2}\xi^2\right)$$ is the probability density function of the standard normal distribution and $$\Phi(\cdot)$$ is its cumulative distribution function $$\Phi(x) = \frac{1}{2} \left( 1+\operatorname{erf}(x/\sqrt{2}) \right).$$ By definition, if $$b=\infty$$, then $$\Phi\left(\tfrac{b - \mu}{\sigma}\right) =1$$, and similarly, if $$a = -\infty$$, then $$\Phi\left(\tfrac{a - \mu}{\sigma}\right) = 0$$.

The above formulae show that when $$-\infty<a<b<+\infty$$ the scale parameter $$\sigma^2$$ of the truncated normal distribution is allowed to assume negative values. The parameter $$\sigma$$ is in this case imaginary, but the function $$f$$ is nevertheless real, positive, and normalizable. The scale parameter $$\sigma^2$$ of the untruncated normal distribution must be positive because the distribution would not be normalizable otherwise. The doubly truncated normal distribution, on the other hand, can in principle have a negative scale parameter (which is different from the variance, see summary formulae), because no such integrability problems arise on a bounded domain. In this case the distribution cannot be interpreted as an untruncated normal conditional on $$ a < X < b $$, of course, but can still be interpreted as a maximum-entropy distribution with first and second moments as constraints, and has an additional peculiar feature: it presents two local maxima instead of one, located at $$x=a$$ and $$x=b$$.

Properties
The truncated normal is one of two possible maximum entropy probability distributions for a fixed mean and variance constrained to the interval [a,b], the other being the truncated U. Truncated normals with fixed support form an exponential family. Nielsen reported closed-form formula for calculating the Kullback-Leibler divergence and the Bhattacharyya distance between two truncated normal distributions with the support of the first distribution nested into the support of the second distribution.

Moments
If the random variable has been truncated only from below, some probability mass has been shifted to higher values, giving a first-order stochastically dominating distribution and hence increasing the mean to a value higher than the mean $$\mu$$ of the original normal distribution. Likewise, if the random variable has been truncated only from above, the truncated distribution has a mean less than $$\mu.$$

Regardless of whether the random variable is bounded above, below, or both, the truncation is a mean-preserving contraction combined with a mean-changing rigid shift, and hence the variance of the truncated distribution is less than the variance $$\sigma^2$$ of the original normal distribution.

==== Two sided truncation ====

Let $$\alpha = (a-\mu)/\sigma$$ and $$\beta = (b-\mu)/\sigma $$. Then: $$ \operatorname{E}(X \mid a<X<b) = \mu - \sigma\frac{\varphi(\beta) - \varphi(\alpha)}{\Phi(\beta)-\Phi(\alpha)} $$ and $$ \operatorname{Var}(X \mid a<X<b) = \sigma^2\left[ 1 - \frac{\beta\varphi(\beta) - \alpha\varphi(\alpha)}{\Phi(\beta)-\Phi(\alpha)} -\left(\frac{\varphi(\beta) - \varphi(\alpha)}{\Phi(\beta)-\Phi(\alpha)}\right)^2\right]$$

Care must be taken in the numerical evaluation of these formulas, which can result in catastrophic cancellation when the interval $$[a,b]$$ does not include $$\mu$$. There are better ways to rewrite them that avoid this issue.

==== One sided truncation (of lower tail) ==== In this case $$\; b=\infty, \; \varphi(\beta)=0, \; \Phi(\beta)=1,$$ then

$$ \operatorname{E}(X \mid X>a) = \mu +\sigma \varphi(\alpha)/Z ,\!$$

and

$$ \operatorname{Var}(X \mid X>a) = \sigma^2[1+ \alpha \varphi(\alpha)/Z- (\varphi(\alpha)/Z)^2 ],$$

where $$ Z=1-\Phi(\alpha). $$

One sided truncation (of upper tail)
In this case $$\; a=\alpha=-\infty, \; \varphi(\alpha)=0, \; \Phi(\alpha) = 0,$$ then

$$ \operatorname{E}(X \mid X<b) = \mu -\sigma\frac{\varphi(\beta)}{\Phi(\beta)} ,$$ $$ \operatorname{Var}(X \mid X<b) = \sigma^2\left[1-\beta \frac{\varphi(\beta)}{\Phi(\beta)}- \left(\frac{\varphi(\beta)}{\Phi(\beta)} \right)^2\right].$$

give a simpler expression for the variance of one sided truncations. Their formula is in terms of the chi-square CDF, which is implemented in standard software libraries. provide formulas for (generalized) confidence intervals around the truncated moments.

A recursive formula
As for the non-truncated case, there is a recursive formula for the truncated moments.

Multivariate
Computing the moments of a multivariate truncated normal is harder.

Generating values from the truncated normal distribution
A random variate $$x$$ defined as $$ x = \Phi^{-1}( \Phi(\alpha) + U\cdot(\Phi(\beta)-\Phi(\alpha)))\sigma + \mu $$ with $$\Phi$$ the cumulative distribution function and $$\Phi^{-1}$$ its inverse, $$U$$ a uniform random number on $$(0, 1)$$, follows the distribution truncated to the range $$(a, b)$$. This is simply the inverse transform method for simulating random variables. Although one of the simplest, this method can either fail when sampling in the tail of the normal distribution, or be much too slow. Thus, in practice, one has to find alternative methods of simulation.

One such truncated normal generator (implemented in Matlab and in R (programming language) as trandn.R ) is based on an acceptance rejection idea due to Marsaglia. Despite the slightly suboptimal acceptance rate of in comparison with,  Marsaglia's method is typically  faster, because it does not require the costly numerical evaluation of the exponential function.

For more on simulating a draw from the truncated normal distribution, see, ,. The MSM package in R has a function, rtnorm, that calculates draws from a truncated normal. The truncnorm package in R also has functions to draw from a truncated normal.

proposed (arXiv) an algorithm inspired from the Ziggurat algorithm of Marsaglia and Tsang (1984, 2000), which is usually considered as the fastest Gaussian sampler, and is also very close to Ahrens's algorithm (1995). Implementations can be found in C, C++, Matlab and Python.

Sampling from the multivariate truncated normal distribution is considerably more difficult. Exact or perfect simulation is only feasible in the case of truncation of the normal distribution to a polytope region. In more general cases,  introduce a general methodology for sampling truncated densities within a Gibbs sampling framework. Their algorithm introduces one latent variable and, within a Gibbs sampling framework, it is more computationally efficient than the algorithm of.