ars: Adaptive Rejection Sampling

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

ars returns a sample of length N from the density function f

Usage

1
ars(f, N, x0 = c(-1.0, 1.0), bounds = c(-Inf, Inf), ...)

Arguments

f

function from which to sample (must be log-concave)

N

number of observations desired

x0

vector of initial x points used to approximate h=log(f(x))

bounds

vector (length 2) of lower and upper bounds for the distribution function f

...

Additional arguments to pass to f

Details

Adaptive Rejection Sampling algorithm for sampling from any univariate log-concave density function f(x). This algorithm is particularly useful in situations where computing f(x) may be expensive, as the number of times f(x) must be sampled scales approximately 3N^1/3, where N is the total number of samples, which is significantly more efficient than conventional rejection sampling. Also, f(x) is not required to be normalized.

IMPORTANT: x0 must satisfy the following conditions:

At least one of dh(x0)/dx must be positive or the left bound must not be -Inf

AND

At least one of dh(x0)/dx must be negative or the right bound must not be Inf.

Value

returns (length N) vector of samples from the density function f(x)

Author(s)

Jonathan Morrell, Ziyang Zhou, Vincent Zijlmans

References

Gilks, W. R., et al. (1995-01-01). "Adaptive Rejection Metropolis Sampling within Gibbs Sampling". Journal of the Royal Statistical Society. Series C (Applied Statistics). 44 (4): 455–472.

See Also

Wikipedia entry on Rejection Sampling.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
N <- 10000
x <- ars(dnorm, N)
x <- ars(dexp, N, x0=c(1.0), bounds=c(0.0, Inf))
x <- ars(dgamma, N, x0=c(2.5), bounds=c(0.0, Inf), shape=3.0, rate=2.0)
## Could use hist to visualize distribution, e.g.
## hist(x, breaks = 50, freq=FALSE)

The following will produce an error
## Not run: 
x <- ars(dgamma, N, x0=c(0.1), bounds=c(0.0, Inf), shape=3.0, rate=2.0)

## End(Not run)

jtmorrell/ars documentation built on May 7, 2019, 10:47 p.m.