Description Usage Arguments Value Author(s) Examples
This is the main function of the MATH 4800 project. It recieves a function's pdf and generates a number of samples from the rv with the provided pdf using rejection sampling. It is thereby somewhat similar to functions such as rbinom, runif, etc.
1 | rejection_sampling(n = 1, pdf, a = 0, b = 1, C)
|
n |
is the number of samples to generate. |
pdf |
is the pdf of the random variable you wish to sample from. |
a |
is the lower bound of the random variable you wish to sample from. |
b |
is the upper bound of the random variable you wish to sample from. |
C |
is a numeric such that f(x) <= C for all values of x. |
my_sample A vector containg the desired number of random samples from the desired distribution.
Peter Reiker
1 2 3 | rejection_sampling(10^4, function(x)1, 0, 1, 1)
rejection_sampling(10^4, function(x)2*x, 0, 1, 2)
rejection_sampling(10^4, function(x)exp(-x), 0, 10, 1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.