naginterfaces.library.stat.inv_​cdf_​gamma

naginterfaces.library.stat.inv_cdf_gamma(p, a, b, tol=0.0)[source]

inv_cdf_gamma returns the deviate associated with the given lower tail probability of the gamma distribution.

For full information please refer to the NAG Library document for g01ff

https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/g01/g01fff.html

Parameters
pfloat

, the lower tail probability from the required gamma distribution.

afloat

, the shape parameter of the gamma distribution.

bfloat

, the scale parameter of the gamma distribution.

tolfloat, optional

The relative accuracy required by you in the results. The smallest recommended value is , where . If inv_cdf_gamma is entered with less than or greater or equal to , then is used instead.

Returns
xfloat

The deviate associated with the given lower tail probability of the gamma distribution.

Raises
NagValueError
(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

The probability is too close to for the given to enable the result to be calculated.

(errno )

The series used to calculate the gamma function has failed to converge. This is an unlikely error exit.

Warns
NagAlgorithmicWarning
(errno )

The algorithm has failed to converge in iterations. A larger value of should be tried. The result may be a reasonable approximation.

Notes

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