trandn: Fast truncated normal generator

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/trandn.R

Description

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]. Infinite values for u and l are accepted.

Usage

1
trandn(l, u)

Arguments

l

lower truncation limit

u

upper truncation limit

Details

Suppose we wish to simulate a random variable Z drawn from N(μ,σ^2) and conditional on l<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

Value

random variable drawn from the truncated normal distribution

Note

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

Author(s)

Zdravko I. Botev

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

Examples

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

Example output

Loading required package: randtoolbox
Loading required package: rngWELL
This is randtoolbox. For an overview, type 'help("randtoolbox")'.
[1] 1.057498
 [1] 1.317404 1.481899 1.267103 1.471188 2.326462 1.805832 1.885492 1.489763
 [9] 1.904807 1.464832

TruncatedNormal documentation built on Sept. 8, 2021, 5:07 p.m.