ars.new {Runuran}R Documentation

UNU.RAN generator based on Adaptive Rejection Sampling (ARS)

Description

UNU.RAN random variate generator for continuous distributions with given probability density function (PDF). It is based on Adaptive Rejection Sampling (‘ARS’).

[Universal] – Rejection Method.

Usage

ars.new(logpdf, dlogpdf=NULL, lb, ub, ...)

Arguments

logpdf log-density function. (R function)
dlogpdf derivative of logpdf. (R function)
lb lower bound of domain; use -Inf if unbounded from left. (numeric)
ub upper bound of domain; use Inf if unbounded from right. (numeric)
... (optional) arguments for logpdf

Details

This function creates a unuran object based on ‘ARS’ (Adaptive Rejection Sampling). It can be used to draw samples from continuous distributions with given probability density function using ur.

The log-density must be provided by a function logpdf which need not be normalized (i.e., it can be a log-density plus some arbitrary constant). Moreover, the given function must be concave (i.e., the distribution must be log-concave).

The derivative dlogpdf is optional. If omitted, numerical differentiation is used. Notice, however, that this might cause some round-off errors such that the algorithm fails.

The setup time of this method depends on the given PDF, whereas its marginal generation times are almost independent of the target distribution.

‘ARS’ is a special case of method ‘TDR’ (see tdr.new). It is a bit slower and less flexible but numerically more stable. In particular, it is useful if one wants to sample from truncated distributions with extreme truncation points; or when the integral of the given “density” function is only known to be extremely large or small. However, this assumes that the log-density is computed analytically and not by just using log(pdf(x)).

Author(s)

Josef Leydold and Wolfgang H"ormann unuran@statmath.wu-wien.ac.at.

References

W. H"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg. See Chapter 4 (Tranformed Density Rejection).

W. R. Gilks and P. Wild (1992): Adaptive rejection sampling for Gibbs sampling. Applied Statistics 41(2), pp. 337–348.

See Also

ur, tdr.new, unuran.new, unuran.

Examples

## Create a sample of size 100 for a 
## Gaussian distribution (use logPDF)
lpdf <- function (x) { -0.5*x^2 }
gen <- ars.new(logpdf=lpdf, lb=-Inf, ub=Inf)
x <- ur(gen,100)

## Same example but additionally provide derivative of log-density
## to prevent possible round-off errors
lpdf <- function (x) { -0.5*x^2 }
dlpdf <- function (x) { -x }
gen <- ars.new(logpdf=lpdf, dlogpdf=dlpdf, lb=-Inf, ub=Inf)
x <- ur(gen,100)

## Draw a sample from a truncated Gaussian distribution
## on domain [100,Inf)
lpdf <- function (x) { -0.5*x^2 }
gen <- ars.new(logpdf=lpdf, lb=50, ub=Inf)
x <- ur(gen,100)


[Package Runuran version 0.9.0 Index]