oneDsample: Single variable Rejection Sampling

Description Usage Arguments Value Examples

Description

This function 'oneDsample(f,N,lb,up,method)' implements single variable rejection sampling for continuous rvs with or without bounded support. Additionally, the function 'oneDsampleplot()' and 'oneDsamplehist()' shows the plot of original function and simulation density function.

Usage

1
oneDsample(f, N = 50000, lb = Inf, ub = Inf, method = "best")

Arguments

f

The pdf that we are sampling from

N

The number of attempted samples. Default value is 50000.

lb

lower bound of support of f. Default value is Inf.

ub

upper bound of support of f. Default value is Inf.

method

There are three method you can choose, 'norm', 't' or 'unif'. Defalt method will be the best method we select for your pdf

Value

A vector containing samples from pdf (including NA) ggplot of original function(red) and simulation density function histogram of simulation density function

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
f<- function(x) {ifelse(-1< x & x < 0, 2*(x+1), 0)}
oneDsampleplot(oneDsample(f,20000,-1,0,method='unif'))

f<- function(x) dlnorm(x,mean=0,sdlog=1)
oneDsampleplot(oneDsample(f,50000,'norm'))

f<- function(x) dnorm(x,-10,2)
oneDsampleplot(oneDsample(f,method='t'))

f = function(x) {ifelse(0 <= x & x <= 2*pi ,1/2/pi *(sin(x) + 1),0)}
oneDsampleplot(oneDsample(f,50000,0,2*pi))

sissidong/4800-project documentation built on May 12, 2019, 8:45 a.m.