Description Usage Arguments Details Value Author(s) References Examples
Sample from Truncated Normal distributions
| 1 2 | 
| .mean | Length K vector with the means of the K Normal distributions prior to truncation | 
| .sd | Length K vector with the standard deviations of the K Normal distributions prior to truncation | 
| .low | Length K vector with the lower truncation bound of the K Normal distributions prior to truncation | 
| .high | Length K vector with the upper truncation bound of the K Normal distributions prior to truncation | 
| .checks | Length 1 logical vector indicating whether to perform checks (safer) or not (faster) on the input parameters | 
The special values of -Inf and Inf are valid values in the .low and .high arguments, respectively. The implementation is from Robert (1995). The computation is written in Rcpp-based C++ code, but respects R's RNG state. The draws from this function are reproducible because it respects R's RNG state. Draws using this algorithm (whether implemented in R code or C++) will be the same if seeded correctly. However, you should not expect these draws to match those from another algorithm.
A length K vector of expectations corresponding to the Truncated Normal distributions. NAs are returned (with a warning) for invalid parameter values.
Jonathan Olmsted
Robert, Christian P. “Simulation of truncated normal variables”. Statistics and Computing 5.2 (1995): 121-125. http://dx.doi.org/10.1007/BF00143942
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | set.seed(1)
rtn(0, 1, -Inf, Inf) # single draw from a single distribution
## [1] -0.6264538
set.seed(1)
rtn(0, 1, -Inf, Inf) # again, because it respects the RNG state
## [1] -0.6264538
rtn(rep(0, 3),
    rep(1, 3),
    rep(-Inf, 3),
    rep(Inf, 3)
    ) # multiple draws from a single distribution
## [1]  0.1836433 -0.8356286  1.5952808
rtn(c(0, 0),
    c(1, 1),
    c(-Inf, 5),
    c(1, Inf)
    ) # multiple draws, each from a different distribution
## [1] 0.3295078 5.3917301
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.