The function provides efficient state-of-the-art random number generation of a vector of truncated univariate distribution of the same length as the lower bound vector. The function is vectorized and the vector of means mu and of standard deviations sd are recycled.

If mu or sd are not specified they assume the default values of 0 and 1, respectively.

Arguments

n

number of observations

p

vector or matrix of probabilities

mu

vector of means

sd

vector of standard deviations

lb

vector of lower truncation limits

ub

vector of upper truncation limits

method

string, either of fast or invtransfo

Value

vector or matrix of random variates (rtnorm) or of quantiles (ptnorm), depending on the input

Examples

rtnorm(n = 10, mu = 2, lb = 1:10, ub = 2:11, method = "fast")
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] #> [1,] 1.690845 2.276538 3.425123 4.273309 5.113333 6.206615 7.247443 8.354474 #> [2,] 1.741832 2.722166 3.065937 4.413829 5.055884 6.249902 7.061502 8.000345 #> [3,] 1.288643 2.982738 3.063855 4.497565 5.100515 6.143544 7.010709 8.132245 #> [4,] 1.218148 2.252800 3.620495 4.689569 5.219608 6.323855 7.065482 8.092172 #> [5,] 1.641487 2.351880 3.145198 4.090533 5.189413 6.676028 7.057719 8.731218 #> [6,] 1.657140 2.062316 3.424318 4.423197 5.064318 6.173693 7.044871 8.081815 #> [7,] 1.063151 2.087686 3.748561 4.819479 5.132200 6.021939 7.185474 8.012355 #> [8,] 1.367935 2.016930 3.191876 4.200731 5.039241 6.170118 7.330431 8.227029 #> [9,] 1.468608 2.515565 3.859525 4.235543 5.474273 6.075684 7.216048 8.331361 #> [10,] 1.920902 2.124748 3.369653 4.342146 5.581330 6.174324 7.010696 8.255417 #> [,9] [,10] #> [1,] 9.045800 10.04509 #> [2,] 9.241725 10.13698 #> [3,] 9.089766 10.30935 #> [4,] 9.027193 10.00749 #> [5,] 9.001278 10.02309 #> [6,] 9.016496 10.00560 #> [7,] 9.154392 10.11272 #> [8,] 9.042628 10.14005 #> [9,] 9.341344 10.63645 #> [10,] 9.448827 10.01714
qtnorm(runif(10), mu = 2, lb = 1:10, ub = 2:11, sd = 1)
#> [1] 1.024057 2.759709 3.130645 4.130964 5.530116 6.572874 7.046861 #> [8] 8.431139 9.198102 10.144631