Learn R Programming

Runuran (version 0.40)

tabl.new: UNU.RAN generator based on TABLe based Rejection (TABL)

Description

UNU.RAN random variate generator for continuous distributions with given probability density function (PDF). It is based on the TABLe based rejection method (‘TABL’).

[Universal] -- Rejection Method.

Usage

tabl.new(pdf, lb, ub, mode, islog=FALSE, ...)
tabld.new(distr)

Value

An object of class "unuran".

Arguments

pdf

probability density 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)

mode

location of the mode. (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 an unuran object based on ‘TABL’ (TABLe based 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 given pdf must be unimodal.

Alternatively, one can use function tabld.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 (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg. See Section 5.1 (“Ahrens Method”).

See Also

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

Examples

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

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

## Draw sample from Gaussian distribution with mean 1 and
## standard deviation 2. Use 'dnorm'.
gen <- tabl.new(pdf=dnorm, lb=-Inf, ub=Inf, mode=1, 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 <- tabl.new(pdf=logpdf, lb=5, ub=Inf, mode=5, islog=TRUE)
x <- ur(gen,100)

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

Run the code above in your browser using DataLab