rejection_sampling: Single Variable Rejection Sampling

Description Usage Arguments Value Author(s) Examples

Description

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.

Usage

1
rejection_sampling(n = 1, pdf, a = 0, b = 1, C)

Arguments

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.

Value

my_sample A vector containg the desired number of random samples from the desired distribution.

Author(s)

Peter Reiker

Examples

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)

reikerp/contdistpeter documentation built on May 26, 2019, 2:32 p.m.