hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_stat_inv_cdf_gamma (g01ff)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_stat_inv_cdf_gamma (g01ff) returns the deviate associated with the given lower tail probability of the gamma distribution.

Syntax

[result, ifail] = g01ff(p, a, b, 'tol', tol)
[result, ifail] = nag_stat_inv_cdf_gamma(p, a, b, 'tol', tol)
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, gp, associated with the lower tail probability, p, of the gamma distribution with shape parameter α and scale parameter β, is defined as the solution to
PGgp:α,β=p=1βαΓα 0gpe-G/βGα-1dG,  0gp<;α,β>0.  
The method used is described by Best and Roberts (1975) making use of the relationship between the gamma distribution and the χ2-distribution.
Let y=2 gpβ . The required y is found from the Taylor series expansion
y=y0+rCry0 r! Eϕy0 r,  
where y0 is a starting approximation
For most values of p and α the starting value
y01=2α z19α +1-19α 3  
is used, where z is the deviate associated with a lower tail probability of p for the standard Normal distribution.
For p close to zero,
y02= pα2αΓ α 1/α  
is used.
For large p values, when y01>4.4α+6.0,
y03=-2ln1-p-α-1ln12y01+lnΓ α  
is found to be a better starting value than y01.
For small α α0.16, p is expressed in terms of an approximation to the exponential integral and y04 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 χ2 distribution Appl. Statist. 24 385–388

Parameters

Compulsory Input Parameters

1:     p – double scalar
p, the lower tail probability from the required gamma distribution.
Constraint: 0.0p<1.0.
2:     a – double scalar
α, the shape parameter of the gamma distribution.
Constraint: 0.0<a106.
3:     b – double scalar
β, the scale parameter of the gamma distribution.
Constraint: b>0.0.

Optional Input Parameters

1:     tol – double scalar
Default: 0.0
The relative accuracy required by you in the results. The smallest recommended value is 50×δ, where δ=max10-18,machine precision. If nag_stat_inv_cdf_gamma (g01ff) is entered with tol less than 50×δ or greater or equal to 1.0, then 50×δ is used instead.

Output Parameters

1:     result – double scalar
The result of the function.
2:     ifail int64int32nag_int scalar
ifail=0 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 ifail=1, 2, 3 or 5, then nag_stat_inv_cdf_gamma (g01ff) returns 0.0.

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

   ifail=1
On entry,p<0.0,
orp1.0,
   ifail=2
On entry,a0.0,
ora>106,
orb0.0
   ifail=3
p is too close to 0.0 or 1.0 to enable the result to be calculated.
W  ifail=4
The solution has failed to converge in 100 iterations. A larger value of tol should be tried. The result may be a reasonable approximation.
   ifail=5
The series to calculate the gamma function has failed to converge. This is an unlikely error exit.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
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 p 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.
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)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015