oneDsample: Single variable Rejection Sampling

Description Usage Arguments Value Examples

Description

This function implements single variabel rejection sampling for rvs with bounded support and which have have bounded pdf.

Usage

1
oneDsample(f, N, lb = -Inf, ub = Inf, discrete = FALSE)

Arguments

f

the pdf that we are sampling from

N

the number of attempted samples.

lb

lower bound of support of f

ub

upper bound of support of f

Value

A vector containing samples from pdf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
f <- function(x) {ifelse(0 < x & x < 1, 4*x^3, 0)}
a <- oneDsample(f,10000)
ggplot(a,aes(x)) + geom_density() + stat_function(fun = f, color = "red")

f <- function(x) {1/pi/(1+x^2)}
a <- oneDsample(f,20000)
ggplot(a,aes(x)) + geom_density() + stat_function(fun = f, color = "red")

f <- function(x) {dunif(x, -100, 100)}
a <- oneDsample(f,50000, -100, 100)
a <- oneDsample(f,500)
ggplot(a,aes(x)) + geom_density() + stat_function(fun = f, color = "red")

pinhuang0317/4800.Final.Project-KC.P.Production- documentation built on May 28, 2019, 7:37 a.m.