trandn function

Fast truncated normal generator

Fast truncated normal generator

Efficient state-of-the-art generator of a vector of length(l)=length(u)

from the standard multivariate normal distribution truncated over the region [l,u][l,u]. Infinite values for u and l are accepted.

trandn(l, u)

Arguments

  • l: lower truncation limit
  • u: upper truncation limit

Returns

random variable drawn from the truncated normal distribution

Details

Suppose we wish to simulate a random variable ZZ drawn from N(μ,σ2)N(\mu,\sigma^2) and conditional on l<Z<ul<Z<u using the inverse transform method. To achieve this, first compute X=norminvp(runif(1),(l-mu)/sig,(u-mu)/sig) and then set Z=mu+sig*X

Note

Use norminvp for the (slower) inverse transform method of simulating truncated normal variables.

Examples

trandn(l = 1,u = Inf) trandn(l = rep(1, 10), u = rep(Inf, 10))

References

Z. I. Botev (2017), The Normal Law Under Linear Restrictions: Simulation and Estimation via Minimax Tilting, Journal of the Royal Statistical Society, Series B, 79 (1), pp. 1--24.

See Also

norminvp

Author(s)

Zdravko I. Botev

  • Maintainer: Leo Belzile
  • License: GPL-3
  • Last published: 2024-07-08

Useful links