Truncated normal distribution
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. For example, it is used to model the probabilities of the binary outcomes in the probit model and to model censored data in the tobit model. Definitions. Suppose formula_1 has a normal distribution with mean formula_2 and variance formula_3 and lies within the interval formula_4. Then formula_5 conditional on formula_6 has a truncated  normal distribution. Its probability density function, formula_7, for formula_8, is given by and by formula_10 otherwise. Here, is the probability density function of the standard normal distribution and formula_12 is its cumulative distribution function By definition, if formula_14, then formula_15, and similarly, if formula_16, then formula_17. The above formulae show that when <math>-\infty the scale parameter formula_3 of the truncated normal distribution is allowed to assume negative values. The parameter formula_19 is in this case imaginary, but the function formula_7 is nevertheless real, positive, and normalizable. The scale parameter formula_3 of the "canonical" 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 a canonical normal conditional on formula_6, 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 formula_23 and formula_24. Properties. The truncated  normal is the maximum entropy probability distribution for a fixed mean and variance, with the random variate "X" constrained to be in the interval [a,b]. 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 formula_2 of the original normal distribution. Likewise, if the random variable has been truncated only from above, the truncated distribution has a mean less than formula_26 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 formula_3 of the original normal distribution. Two sided truncation. Let formula_28 and formula_29. Then: One sided truncation (of lower tail). In this case formula_32 then and where formula_35 One sided truncation (of upper tail). In this case formula_36 then with formula_38 the cumulative distribution function and formula_39 its inverse, formula_40 a uniform random number on formula_41, follows the distribution truncated to the range formula_42. 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 Marsaglia (1964) in comparison with Robert (1995), 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 Robert (1995), Lynch (2007) Section 8.1.3 (pages 200–206), Devroye (1986). 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. Chopin (2011) 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.