PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_rand_dist_gamma (g05sj)
Purpose
nag_rand_dist_gamma (g05sj) generates a vector of pseudorandom numbers taken from a gamma distribution with parameters and .
Syntax
Description
The gamma distribution has PDF (probability density function)
One of three algorithms is used to generate the variates depending upon the value of
:
(i) |
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 Ahrens and Dieter's GS algorithm (see Ahrens and Dieter (1974)) in which ; |
(ii) |
if , 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 , 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. |
One of the initialization functions
nag_rand_init_repeat (g05kf) (for a repeatable sequence if computed sequentially) or
nag_rand_init_nonrepeat (g05kg) (for a non-repeatable sequence) must be called prior to the first call to
nag_rand_dist_gamma (g05sj).
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
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
, the number of pseudorandom numbers to be generated.
Constraint:
.
- 2:
– double scalar
-
, the parameter of the gamma distribution.
Constraint:
.
- 3:
– double scalar
-
, the parameter of the gamma distribution.
Constraint:
.
- 4:
– int64int32nag_int array
-
Note: the actual argument supplied
must be the array
state supplied to the initialization routines
nag_rand_init_repeat (g05kf) or
nag_rand_init_nonrepeat (g05kg).
Contains information on the selected base generator and its current state.
Optional Input Parameters
None.
Output Parameters
- 1:
– int64int32nag_int array
-
Contains updated information on the state of the generator.
- 2:
– double array
-
The pseudorandom numbers from the specified gamma distribution.
- 3:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
Constraint: .
-
-
Constraint: .
-
-
Constraint: .
-
-
On entry,
state vector has been corrupted or not initialized.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
Not applicable.
Further Comments
None.
Example
This example prints a set of five pseudorandom numbers from a gamma distribution with parameters
and
, generated by a single call to
nag_rand_dist_gamma (g05sj), after initialization by
nag_rand_init_repeat (g05kf).
Open in the MATLAB editor:
g05sj_example
function g05sj_example
fprintf('g05sj example results\n\n');
seed = [int64(1762543)];
genid = int64(1);
subid = int64(1);
[state, ifail] = g05kf( ...
genid, subid, seed);
n = int64(5);
a = 5;
b = 1;
[state, x, ifail] = g05sj( ...
n, a, b, state);
disp('Variates');
disp(x);
g05sj example results
Variates
5.0702
6.1337
3.1018
3.9863
4.9648
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015