ars: Adaptive Rejection Sampling

Description Usage Arguments Value Examples

Description

Adaptive Rejection Sampling from log-concave density functions h(x)

Usage

1
ars(h, start, end, N, k = 3, x1 = NULL, xk = NULL)

Arguments

h

input the original valid probability density function we want to sample from, the function h should only takes one argument x. i.e. correct: h = function(x) {dnorm(x,0,1)}; wrong: h = function(x,mean = 0,sd = 1) {dnorm(x,mean,sd)}

start

lower bound of the domain of h(x)

end

upper bound of the domain of h(x)

N

sample size

k

number of starting points, the default is 3

x1

the right starting point, if NULL, the function will find one

xk

the left starting point, if NULL, the function will find one

Value

a vector of N sampled value from the density h(x)

Examples

1
2
3
4
library(ars)
h = function(x){dnorm(x)}
sample = ars(h = h,start = -Inf , end = Inf,N = 100)
hist(sample)

kaiwei-berkeley/ars documentation built on May 21, 2019, 10:12 a.m.