pinv.new {Runuran}R Documentation

UNU.RAN generator based on Polynomial interpolation of INVerse CDF (PINV)

Description

UNU.RAN random variate generator for continuous distributions with given probability density function (PDF) or cumulative distribution function (CDF). It is based on the Polynomial interpolation of INVerse CDF (‘PINV’).

[Universal] – Inversion Method.

Usage

pinv.new(pdf, cdf, lb, ub, islog=FALSE, center=0, uresolution=1.e-10, ...)

Arguments

pdf probability density function. (R function)
cdf cumulative distribution function. (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 and cdf are given by their corresponding logarithms. (boolean)
center “typical” point of distribution. (numeric)
uresolution maximal acceptable u-error. (numeric)
... (optional) arguments for pdf and cdf.

Details

This function creates an unuran object based on ‘PINV’ (Polynomial interpolation of INVerse CDF). It can be used to draw samples of a continuous random variate with given probability density function pdf or cumulative distribution function cdf by means of ur. It also allows to compute quantiles by means of uq.

pdf is (a multiple of) a density, i.e., it must return non-negative numbers but need not integrate to 1. However, the set of points where the pdf is strictly positive must be connected. The algorithm then automatically computes the CDF using Gauss-Lobatto integration.

If the cdf is given but not the pdf then the CDF is used instead of the PDF. However, we found in our experiments that using the PDF is numerically more stable.

The center must be a point where the pdf is not too small, e.g., (a point near) the mode of the distribution. By default 0. is assumed.

The algorithms approximates the inverse of the CDF of the distribution. The distribution error is estimated by means of the the u-error, i.e., |CDF(G(U)) - U|, where G denotes the approximation of the inverse CDF. The error can be controlled by means of argument uresolution.

When sampling from truncated distributions with extreme truncation points, it is recommended to provide the log-density by setting islog=TRUE. Then the algorithm is numerically more stable.

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

Author(s)

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

References

G. Derflinger, W. H"ormann, and J. Leydold (2009): in preparation.

See Also

ur, uq, unuran.new, unuran.

Examples

## Create a sample of size 100 for a Gaussian distribution
pdf <- function (x) { exp(-0.5*x^2) }
gen <- pinv.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 <- pinv.new(pdf=logpdf, 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 <- pinv.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 [2,Inf)
gen <- pinv.new(pdf=dnorm, lb=2, ub=Inf)
x <- ur(gen,100)

## Improve the accuracy of the approximation
gen <- pinv.new(pdf=dnorm, lb=-Inf, ub=Inf, uresolution=1e-15)
x <- ur(gen,100)

## We have to provide a 'center' when PDF (almost) vanishes at 0.
gen <- pinv.new(pdf=dgamma, lb=0, ub=Inf, center=4, shape=5)
x <- ur(gen,100)

[Package Runuran version 0.9.0 Index]