The gamma distribution has PDF (probability density function)
One of three algorithms is used to generate the variates depending upon the value of
$a$:
(i) |
if $a<1$, a switching algorithm described by Dagpunar (1988) (called G6) is used. The target distributions are ${f}_{1}\left(x\right)=ca{x}^{a-1}/{t}^{a}$ and ${f}_{2}\left(x\right)=\left(1-c\right){e}^{-\left(x-t\right)}$, where $c=t/\left(t+a{e}^{-t}\right)$, and the switching parameter, $t$, is taken as $1-a$. This is similar to Ahrens and Dieter's GS algorithm (see Ahrens and Dieter (1974)) in which $t=1$; |
(ii) |
if $a=1$, the gamma distribution reduces to the exponential distribution and the method based on the logarithmic transformation of a uniform random variate is used; |
(iii) |
if $a>1$, the algorithm given by Best (1978) is used. This is based on using a Student's $t$-distribution with two degrees of freedom as the target distribution in an envelope rejection method. |
One of the initialization functions
nag_rand_init_repeatable (g05kfc) (for a repeatable sequence if computed sequentially) or
nag_rand_init_nonrepeatable (g05kgc) (for a non-repeatable sequence) must be called prior to the first call to
nag_rand_gamma (g05sjc).
Ahrens J H and Dieter U (1974) Computer methods for sampling from gamma, beta, Poisson and binomial distributions Computing 12 223–46
Not applicable.
Please consult the
x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
None.
This example prints a set of five pseudorandom numbers from a gamma distribution with parameters
$a=5.0$ and
$b=1.0$, generated by a single call to
nag_rand_gamma (g05sjc), after initialization by
nag_rand_init_repeatable (g05kfc).
None.