Learn R Programming

Runuran (version 0.40)

itdr.new: UNU.RAN generator based on Inverse Transformed Density Rejection (ITDR)

Description

UNU.RAN random variate generator for continuous distributions with given probability density function (PDF). It is based on the Inverse Transformed Density Rejection method (‘ITDR’).

[Universal] -- Rejection Method.

Usage

itdr.new(pdf, dpdf, lb, ub, pole, islog=FALSE, ...)
itdrd.new(distr)

Value

An object of class "unuran".

Arguments

pdf

probability density function. (R function)

dpdf

derivative of pdf. (R function)

pole

pole of distribution. (numeric)

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")

Author

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

Details

This function creates a unuran object based on “ITDR” (Inverse Transformed Density Rejection). 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 algorithm is especially designed for distributions with unbounded densities. Thus the algorithm needs the position of the pole. Moreover, the given function must be monotone on its domain.

The derivative dpdf is essential. (Numerical derivation does not work as it results in serious round-off errors.)

Alternatively, one can use function itdrd.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.

References

W. H\"ormann, J. Leydold, and G. Derflinger (2007): Inverse transformed density rejection for unbounded monotone densities. ACM Trans. Model. Comput. Simul. 17(4), Article 18, 16 pages. DOI: 10.1145/1276927.1276931

See Also

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

Examples

Run this code
## Create a sample of size 100 for a Gamma(0.5) distribution
pdf <- function (x) { x^(-0.5)*exp(-x) }
dpdf <- function (x) { (-x^(-0.5) - 0.5*x^(-1.5))*exp(-x) }
gen <- itdr.new(pdf=pdf, dpdf=dpdf, lb=0, ub=Inf, pole=0)
x <- ur(gen,100)

## Alternative approach
distr <- udgamma(shape=0.5)
gen <- itdrd.new(distr)
x <- ur(gen,100)

Run the code above in your browser using DataLab