Learn R Programming

Runuran (version 0.40)

urgamma: UNU.RAN Gamma random variate generator

Description

UNU.RAN random variate generator for the Gamma distribution with parameters shape and scale. It also allows sampling from the truncated distribution.

[Special Generator] -- Sampling Function: Gamma.

Usage

urgamma(n, shape, scale=1, lb=0, ub=Inf)

Arguments

n

size of required sample.

shape

(strictly positive) shape parameter.

scale

(strictly positive) scale parameter.

lb

lower bound of (truncated) distribution

ub

upper bound of (truncated) distribution

Author

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

Details

If scale is omitted, it assumes the default value of 1.

The Gamma distribution with parameters shape \(=\alpha\) and scale \(=\sigma\) has density $$ f(x)= \frac{1}{{\sigma}^{\alpha}\Gamma(\alpha)} {x}^{\alpha-1} e^{-x/\sigma} $$ for \(x \ge 0\), \(\alpha > 0\) and \(\sigma > 0\). (Here \(\Gamma(\alpha)\) is the function implemented by R's gamma() and defined in its help.)

The generation algorithm uses fast numerical inversion. The parameters lb and ub can be used to generate variates from the Gamma distribution truncated to the interval (lb,ub).

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, and rgamma for the R built-in generator.

Examples

Run this code
## Create a sample of size 1000
x <- urgamma(n=1000,shape=2)

Run the code above in your browser using DataLab