rej_samp {StratPal} | R Documentation |
random numbers from rejection sampling
Description
Rejection sampling from the (pseudo) pdf f
in the interval between x_min
and x_max
. Returns n
samples. Note that values of f
below 0 are capped to zero
Usage
rej_samp(f, x_min, x_max, n = 1L, f_max = 1, max_try = 10^4)
Arguments
f |
function. (pseudo) pdf from which the sample is drawn |
x_min |
number, lower limit of the examined interval |
x_max |
number, upper limit of the examined interval |
n |
integer. number of samples drawn |
f_max |
number, maximum value of |
max_try |
maximum number of tries in the rejection sampling algorithm. If more tries are needed, an error is thrown. If this is the case, inspect of your function |
Value
numeric vector, sample of size n
drawn from the (pseudo) pdf specified by f
See Also
p3_var_rate()
for the derived variable rate Poisson point process implementation.
Examples
f = sin
x = rej_samp(f, 0, 3*pi, n = 100)
hist(x) # note that no samples are drawn where sin is negative