Learn R Programming

Runuran (version 0.5)

urtdr: UNU.RAN transformend density rejection generator

Description

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

Usage

urtdr(n, pdf, dpdf, lb=-Inf, ub=Inf, islog=TRUE, ...)

Arguments

n
size of required sample.
pdf
probability density function. (Rfunction)
dpdf
derivative of the pdf. (Rfunction)
islog
whether the pdf is given by tits logarithm (the dpdf is then the derivative of the logarithm). (boolean)
lb, ub
lower and upper bound of domain. (numeric)
...
(optional) arguments for pdf

Details

This routine generates a sample of continuous random variates with given probability density function. This function must be provided by pdf, a function which must return non-negative numbers and which need not be normalized (i.e., it can be any multiple of a density function). Moreover, the given function must be $T_{-0.5}$-concave distributions (i.e., unimodal densities with tails not higher than $(1/x^2)$; this includes all log-concave distributions). The dpdf is optional. If omitted numerical derivation is used. Notice, however, that this might cause some round-off errors such that generation does not work. This is in particular the case when the density function is provided instead of its logarithm. It uses method TDR (Transformed Density Rejection). 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 (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg.

See Also

runif and .Random.seed about random number generation, unuran for the UNU.RAN class.

Examples

Run this code
## Create a sample of size 10000 for a 
## Gaussian distribution (use logPDF)
logpdf <- function (x) { -0.5*x^2 }
dlogpdf <- function (x) { -x }
x <- urtdr(1000, pdf=logpdf, dpdf=dlogpdf)

## Create a sample of size 10000 for a 
## Gaussian distribution (use logPDF)
logpdf <- function (x) { -0.5*x^2 }
x <- urtdr(1000, pdf=logpdf, islog=TRUE)

## Create a sample of size 10000 for a 
## Gaussian(0,1) distribution (use dnorm)
x <- urtdr(1000, pdf=dnorm, mean=0, sd=1, islog=FALSE)

Run the code above in your browser using DataLab