PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_stat_inv_cdf_gamma (g01ff)
Purpose
nag_stat_inv_cdf_gamma (g01ff) returns the deviate associated with the given lower tail probability of the gamma distribution.
Syntax
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 23: |
tol was made optional (default 0) |
Description
The deviate,
, associated with the lower tail probability,
, of the gamma distribution with shape parameter
and scale parameter
, is defined as the solution to
The method used is described by
Best and Roberts (1975) making use of the relationship between the gamma distribution and the
-distribution.
Let
. The required
is found from the Taylor series expansion
where
is a starting approximation
- ,
- ,
- ,
- ,
- .
For most values of
and
the starting value
is used, where
is the deviate associated with a lower tail probability of
for the standard Normal distribution.
For
close to zero,
is used.
For large
values, when
,
is found to be a better starting value than
.
For small , is expressed in terms of an approximation to the exponential integral and is found by Newton–Raphson iterations.
Seven terms of the Taylor series are used to refine the starting approximation, repeating the process if necessary until the required accuracy is obtained.
References
Best D J and Roberts D E (1975) Algorithm AS 91. The percentage points of the distribution Appl. Statist. 24 385–388
Parameters
Compulsory Input Parameters
- 1:
– double scalar
-
, the lower tail probability from the required gamma distribution.
Constraint:
.
- 2:
– double scalar
-
, the shape parameter of the gamma distribution.
Constraint:
.
- 3:
– double scalar
-
, the scale parameter of the gamma distribution.
Constraint:
.
Optional Input Parameters
- 1:
– double scalar
Default:
The relative accuracy required by you in the results. The smallest recommended value is
, where
. If
nag_stat_inv_cdf_gamma (g01ff) is entered with
tol less than
or greater or equal to
, then
is used instead.
Output Parameters
- 1:
– double scalar
The result of the function.
- 2:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Note: nag_stat_inv_cdf_gamma (g01ff) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:
If on exit , , or , then nag_stat_inv_cdf_gamma (g01ff) returns .
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
-
-
-
-
On entry, | , |
or | , |
or | |
-
-
p is too close to
or
to enable the result to be calculated.
- W
-
The solution has failed to converge in
iterations. A larger value of
tol should be tried. The result may be a reasonable approximation.
-
-
The series to calculate the gamma function has failed to converge. This is an unlikely error exit.
-
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
In most cases the relative accuracy of the results should be as specified by
tol. However, for very small values of
or very small values of
there may be some loss of accuracy.
Further Comments
None.
Example
This example reads lower tail probabilities for several gamma distributions, and calculates and prints the corresponding deviates until the end of data is reached.
Open in the MATLAB editor:
g01ff_example
function g01ff_example
fprintf('g01ff example results\n\n');
p = [ 0.01 0.428 0.869 ];
a = [ 1 7.5 45 ];
b = [ 20 0.1 10 ];
x = p;
fprintf(' p a b x\n');
for j = 1:numel(p)
[x(j), ifail] = g01ff( ...
p(j), a(j), b(j));
end
fprintf('%8.3f%8.3f%8.3f%8.3f\n', [p; a; b; x]);
g01ff example results
p a b x
0.010 1.000 20.000 0.201
0.428 7.500 0.100 0.670
0.869 45.000 10.000 525.839
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015