ars: Adapative Rejection Sampling

Description Usage Arguments Details Value Author(s) References Examples

View source: R/ars.R

Description

'ars' generates random sample from log-concave densify function interested by users using adapative rejection sampling.

Usage

1
ars(N, fn, l = -Inf, u = Inf, center = 0, step = 0.5)

Arguments

N

- numeric: sample size (number of observations).

fn

- function: log-concave function that is proporitional to the sampling density.

l

- numeric: the lower bound of the density function. The default is -Inf.

u

- numeric: the upper bound of the density function. The default is Inf.

center

- numeric: estimated center of function. The default is 0.

step

- numeric: value of bandwidth around center used to find the starting abscissaes. The default is 0.5.

Details

This function takes a numeric argument n and a function argument f to generate random numbers from the given distribution in the specified sample size, based on adapative rejection sampling method. For more detials, see Gilks and Wild (1992).

Value

ars returns a vector of sampled values.

Author(s)

Vincent Myers, Yanting Pan, and Zhenni Ye, based on Gilks and Wild (1992).

References

W. R. Gilks, P. Wild. (1992), "Adaptive Rejection Sampling for Gibbs Sampling," Applied Statistics 41:337<e2><80><93>348.

Examples

1
2
3
4
5
6
7
8
9
##  Sample from Standard Normal Distribution
ars(N = 10000, fn = dnorm, l = -Inf, u = Inf, center = 0, step = 0.5)

## Sample from Gamma Distribution
gamma_test <- function(x){
k <- dgamma(x, shape = 7.5, scale = 1)
return(k)
}
ars(N = 10000, fn = gamma_test, l = 0.1, u = 20)

yantingpan/ars documentation built on May 21, 2019, 10:14 a.m.