oneDSample1: Single Variable Rejection Sampling

Description Usage Arguments Details Value Examples

View source: R/oneDsample1.R

Description

This function implements one variables rejection sampling for rvs with bounded support and which have a bounded pdf.

Usage

1
oneDSample1(f, N = 10000, lb = Inf, ub = Inf, continuous = TRUE)

Arguments

f

the pdf that we are sampling from

N

the number of attempted samples

lb

the lower bound of support

ub

the upper bound of support

Details

Here are more details about the algorithm that we are using

Value

A vector containing samples from pdf

Examples

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

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

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


f<- function(x){dnorm(x,-5000,5000)}
w=oneDSample1(f,50000)
ggplot(w,aes(x)) + geom_density() + stat_function(fun = f, color = "red")

zwang8889/project4800 documentation built on May 29, 2019, 12:20 p.m.