arou.new: UNU.RAN generator based on Automatic Ratio-Of-Uniforms method...

arou.newR Documentation

UNU.RAN generator based on Automatic Ratio-Of-Uniforms method (AROU)

Description

UNU.RAN random variate generator for continuous distributions with given probability density function (PDF). It is based on the Automatic Ratio-Of-Uniforms method (‘AROU’).

[Universal] – Rejection Method.

Usage

arou.new(pdf, dpdf=NULL, lb, ub, islog=FALSE, ...)
aroud.new(distr)

Arguments

pdf

probability density function. (R function)

dpdf

derivative of pdf. (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)

islog

whether pdf is given as log-density (the dpdf must then be the derivative of the log-density). (boolean)

...

(optional) arguments for pdf.

distr

distribution object. (S4 object of class "unuran.cont")

Details

This function creates an unuran object based on ‘AROU’ (Automatic Ratio-Of-Uniforms method). It can be used to draw samples of a continuous random variate with given probability density function using ur.

The density pdf must be positive but need not be normalized (i.e., it can be any multiple of a density function). The derivative dpdf of the (log-) density is optional. If omitted, numerical differentiation is used. Notice, however, that this might cause some round-off errors such that the algorithm fails. This is in particular the case when the density function is provided instead of the log-density.

The given pdf must be T_(-0.5)-concave (with implies unimodal densities with tails not higher than (1/x^2); this includes all log-concave distributions).

It is recommended to use the log-density (instead of the density function) as this is numerically more stable.

Alternatively, one can use function aroud.new where the object distr of class "unuran.cont" must contain all required information about the distribution.

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

Value

An object of class "unuran".

Author(s)

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

References

W. H\"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg. See Section 4.8 (Automatic Ratio-Of-Uniforms).

See Also

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

Examples

## Create a sample of size 100 for a Gaussian distribution
pdf <- function (x) { exp(-0.5*x^2) }
gen <- arou.new(pdf=pdf, lb=-Inf, ub=Inf)
x <- ur(gen,100)

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

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

## Draw sample from Gaussian distribution with mean 1 and
## standard deviation 2. Use 'dnorm'.
gen <- arou.new(pdf=dnorm, lb=-Inf, ub=Inf, mean=1, sd=2)
x <- ur(gen,100)

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

## Alternative approach
distr <- udnorm()
gen <- aroud.new(distr)
x <- ur(gen,100)


Runuran documentation built on Jan. 17, 2023, 5:17 p.m.