NAG Library Function Document
nag_random_gamma (g05ffc)
1 Purpose
nag_random_gamma (g05ffc) generates a vector of pseudorandom variates from a gamma distribution with arguments and .
2 Specification
| #include <nag.h> |
| #include <nagg05.h> |
| void |
nag_random_gamma (double a,
double b,
Integer n,
double x[],
NagError *fail) |
|
3 Description
The gamma distribution has PDF (probability density function):
One of three algorithms is used to generate the variates depending upon the value of
:
If
a switching algorithm described by
Dagpunar (1988) (called G6), is used. The target distributions are
and
, where
, and the switching argument,
, is taken as
. This is similar to GS algorithm of
Ahrens and Dieter (1974) in which
.
If the gamma distribution reduces to the exponential distribution and the method based on the logarithmic transformation of a uniform random variate is used.
If
the algorithm given by
Best (1978) is used. This is based on using a Student's
-distribution with two degrees of freedom as the target distribution in an envelope rejection method.
4 References
Ahrens J H and Dieter U (1974) Computer methods for sampling from gamma, beta, Poisson and binomial distributions Computing 12 223–46
Best D J (1978) Letter to the Editor Appl. Statist. 27 181
Dagpunar J (1988) Principles of Random Variate Generation Oxford University Press
Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth
5 Arguments
- 1:
a – doubleInput
-
On entry: the argument, , of the gamma distribution.
Constraint:
.
- 2:
b – doubleInput
-
On entry: the argument, , of the gamma distribution.
Constraint:
.
- 3:
n – IntegerInput
-
On entry: the number, , of pseudorandom numbers to be generated.
Constraint:
.
- 4:
x[n] – doubleOutput
-
On exit: the pseudorandom variates from the specified gamma distribution.
- 5:
fail – NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error Indicators and Warnings
- NE_INT_ARG_LE
On entry, .
Constraint: .
- NE_REAL_ARG_LE
On entry,
a must not be less than or equal to 0.0:
.
On entry,
b must not be less than or equal to 0.0:
.
7 Accuracy
Not applicable.
To generate an observation from the distribution with degrees of freedom generate an observation from a gamma distribution with arguments , .
To generate an observation,
, from a Student's
-distribution with degrees of freedom
generate an observation,
, from a gamma distribution with arguments
and
and an observation,
, from a standard Normal distribution (see
nag_random_normal (g05ddc)) and use the transformation
.
9 Example
The example program prints a set of five pseudorandom variates from a gamma distribution with arguments
and
, generated by nag_random_gamma (g05ffc) after initialization by
nag_random_init_repeatable (g05cbc).
9.1 Program Text
Program Text (g05ffce.c)
9.2 Program Data
None.
9.3 Program Results
Program Results (g05ffce.r)