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)

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:
Mark 23: tol now optional (default 0)
.

Description

The deviate, gpgp, associated with the lower tail probability, pp, of the gamma distribution with shape parameter αα and scale parameter ββ, is defined as the solution to
gp
P(Ggp : α,β) = p = 1/(βαΓ(α))eG / βGα1dG,  0gp < ;α,β > 0.
0
P(Ggp:α,β)=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χ2-distribution.
Let y = 2(gp)/β y=2 gpβ . The required yy is found from the Taylor series expansion
y = y0 + r(Cr(y0))/(r ! ) (E/(φ(y0)))r,
y=y0+rCr(y0) r! (Eϕ(y0) ) r,
where y0y0 is a starting approximation
For most values of pp and αα the starting value
y01 = 2α (z×sqrt(1/(9α)) + 11/(9α))3
y01=2α (z19α +1-19α ) 3
is used, where zz is the deviate associated with a lower tail probability of pp for the standard Normal distribution.
For pp close to zero,
y02 = (pα2αΓ(α))1 / α
y02= (pα2αΓ (α) ) 1/α
is used.
For large pp values, when y01 > 4.4α + 6.0y01>4.4α+6.0,
y03 = 2[ln(1p)(α1)ln((1/2)y01) + ln(Γ(α))]
y03=-2[ln(1-p)-(α-1)ln(12y01)+ln(Γ (α) ) ]
is found to be a better starting value than y01y01.
For small αα (α0.16)(α0.16), pp is expressed in terms of an approximation to the exponential integral and y04y04 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χ2 distribution Appl. Statist. 24 385–388

Parameters

Compulsory Input Parameters

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

Optional Input Parameters

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

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     result – double scalar
The result of the function.
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=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 = 1ifail=1, 22, 33 or 55, then nag_stat_inv_cdf_gamma (g01ff) returns 0.00.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 = 1ifail=1
On entry,p < 0.0p<0.0,
orp1.0p1.0,
  ifail = 2ifail=2
On entry,a0.0a0.0,
ora > 106a>106,
orb0.0b0.0
  ifail = 3ifail=3
p is too close to 0.00.0 or 1.01.0 to enable the result to be calculated.
W ifail = 4ifail=4
The solution has failed to converge in 100100 iterations. A larger value of tol should be tried. The result may be a reasonable approximation.
  ifail = 5ifail=5
The series to calculate the gamma function has failed to converge. This is an unlikely error exit.

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 pp there may be some loss of accuracy.

Further Comments

None.

Example

function nag_stat_inv_cdf_gamma_example
p = 0.01;
a = 1;
b = 20;
[result, ifail] = nag_stat_inv_cdf_gamma(p, a, b)
 

result =

    0.2010


ifail =

                    0


function g01ff_example
p = 0.01;
a = 1;
b = 20;
[result, ifail] = g01ff(p, a, b)
 

result =

    0.2010


ifail =

                    0



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–2013