Learn R Programming

Runuran (version 0.40)

dari.new: UNU.RAN generator based on Discrete Automatic Rejection Inversion (DARI)

Description

UNU.RAN random variate generator for discrete distributions with given probability mass function (PMF). It is based on Discrete Automatic Rejection Inversion (‘DARI’).

[Universal] -- Rejection Method.

Usage

dari.new(pmf, lb, ub, mode=NA, sum=1, ...)
darid.new(distr)

Value

An object of class "unuran".

Arguments

pmf

probability mass function. (R function)

lb

lower bound of domain; use -Inf if unbounded from left. (numeric, integer)

ub

upper bound of domain; use Inf if unbounded from right. (numeric, integer)

mode

mode of distribution. (integer)

sum

sum over all “probabilities”. (numeric)

...

(optional) arguments for pmf.

distr

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

Author

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

Details

This function creates an unuran object based on ‘DARI’ (Discrete Automatic Rejection Inversion). It can be used to draw samples of a discrete random variate with given probability mass function using ur.

Function pmf must be postive but need not be normalized (i.e., it can be any multiple of a probability mass function).

The given function must be \(T_{-0.5}\)-concave; this includes all log-concave distributions.

In addition the algorithm requires the location of the mode. If omitted then it is computed by a slow numerical search.

If the sum over all probabilities is different from 1 then a rough estimate of this sum is required.

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

References

W. H\"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg. See Section 10.2 (Tranformed Probability Rejection).

See Also

ur, unuran.discr, unuran.new, unuran.

Examples

Run this code
## Create a sample of size 100 for a Binomial distribution
## with 1000 number if observations and probability 0.2
gen <- dari.new(pmf=dbinom, lb=0, ub=1000, size=1000, prob=0.2)
x <- ur(gen,100)

## Create a sample from a distribution with PMF
##  p(x) = 1/x^3, x >= 1  (Zipf distribution)
zipf <- function (x) { 1/x^3 }
gen <- dari.new(pmf=zipf, lb=1, ub=Inf)
x <- ur(gen,100)

## Alternative approach
distr <- udbinom(size=100,prob=0.3)
gen <- darid.new(distr)
x <- ur(gen,100)

Run the code above in your browser using DataLab