Description Usage Arguments Value Examples
View source: R/original/Additional file 2.R View source: R/simulation.R
Resamples supplied distribution to ensure generated values fall within given constraints.
1 | rcon(n, rdist, con, max.iter = 100)
|
n |
Number of samples to draw. |
rdist |
User-defined function for generating random samples
(must take |
con |
Vector of lower and upper constraints on generated samples. |
max.iter |
Maximum number of iterations before aborting. |
A vector of n
values sampled from rdist
such that
the minimum sampled value is greater than or equal to con[1]
and the the maximum is smaller than or equal to con[2]
.
1 2 3 4 5 6 7 8 9 10 11 | # Using default distribution parameters
out <- rcon(10000, rnorm, c(-1, 1))
print(summary(out))
hist(out, 20, xlim=c(-2, 2), probability=TRUE,
main='', xlab='Random variable value')
# Modifying mean and standard deviation
out <- rcon(10000, function(n) {rnorm(n, 0.5, 0.5)}, c(-1, 1))
print(summary(out))
hist(out, 20, xlim = c(-2, 2), probability = TRUE,
main = '', xlab = 'Random variable value')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.