ars: Adaptive-Rejection Sampler

Description Usage Arguments Value Note Author(s) References Examples

View source: R/ars.R

Description

An implementation of the adaptive-rejection sampling algorithm in Gilks, et. al. (1992). It allows one to perform adaptive-rejection sampling on a log-concave density.

Usage

1
ars(FUN, n = 1, D = c(-Inf, Inf))

Arguments

FUN

log-concave density function. Need not be normalized.

n

optional; number of points to sample

D

optional; domain of the density. If unspecified, domain will be -Inf to Inf

Value

Vector of length n containing samples from specified input density.

Note

For a density with extreme domain values, it is suggested first to transform the density to get a smaller mean before feeding it into the algorithm and then to scale it back after the sample is generated. For example, to sample from normal(mean=1000, sd=1), first run ars() with standard normal and then add 1000 to all numbers in the sample.

Author(s)

Vaibhav Ramamoorthy, Jonathan Lee, Colin Kou, Brandon Mannion

References

Gilks, W. R., and P. Wild. <e2><80><9c>Adaptive Rejection Sampling for Gibbs Sampling.<e2><80><9d> Journal of the Royal Statistical Society. Series C (Applied Statistics), vol. 41, no. 2, 1992, pp. 337<e2><80><93>348. JSTOR, JSTOR, www.jstor.org/stable/2347565.

Examples

1
2
3
sample <- ars(dnorm, n = 10000, D = c(-Inf, Inf))
sample <- ars(dnorm, n = 10000, D = c(0, Inf)) # truncated normal
sample <- ars(function(t) dbeta(t, 1, 1), n = 10000, D = c(0, 1))

vaibhavram/ars documentation built on May 24, 2019, 9:55 a.m.