NAG Library Routine Document

g01eff (prob_gamma)

1
Purpose

g01eff returns the lower or upper tail probability of the gamma distribution, with parameters α and β.

2
Specification

Fortran Interface
Function g01eff ( tail, g, a, b, ifail)
Real (Kind=nag_wp):: g01eff
Integer, Intent (Inout):: ifail
Real (Kind=nag_wp), Intent (In):: g, a, b
Character (1), Intent (In):: tail
C Header Interface
#include <nagmk26.h>
double  g01eff_ (const char *tail, const double *g, const double *a, const double *b, Integer *ifail, const Charlen length_tail)

3
Description

The lower tail probability for the gamma distribution with parameters α and β, PGg, is defined by:
P Gg ; α,β = 1 βα Γα 0g Gα-1 e-G/β dG ,   α>0.0 , ​ β>0.0 .  
The mean of the distribution is αβ and its variance is αβ2. The transformation Z=Gβ is applied to yield the following incomplete gamma function in normalized form,
P Gg ; α ,β = P Zg/β : α,1.0 = 1 Γα 0g/β Zα-1 e-Z dZ .  
This is then evaluated using s14baf.

4
References

Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth

5
Arguments

1:     tail – Character(1)Input
On entry: indicates whether an upper or lower tail probability is required.
tail='L'
The lower tail probability is returned, that is PGg:α,β.
tail='U'
The upper tail probability is returned, that is PGg:α,β.
Constraint: tail='L' or 'U'.
2:     g – Real (Kind=nag_wp)Input
On entry: g, the value of the gamma variate.
Constraint: g0.0.
3:     a – Real (Kind=nag_wp)Input
On entry: the parameter α of the gamma distribution.
Constraint: a>0.0.
4:     b – Real (Kind=nag_wp)Input
On entry: the parameter β of the gamma distribution.
Constraint: b>0.0.
5:     ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1 or 1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1 or 1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this argument, the recommended value is 0. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6
Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
If ifail=1, 2, 3 or 4 on exit, then g01eff returns 0.0.
ifail=1
On entry, tail=value.
Constraint: tail='L' or 'U'.
ifail=2
On entry, g=value.
Constraint: g0.0.
ifail=3
On entry, a=value and b=value.
Constraint: a>0.0 and b>0.0.
ifail=4
The algorithm has failed to converge in value iterations. The probability returned should be a reasonable approximation to the solution.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

The result should have a relative accuracy of machine precision. There are rare occasions when the relative accuracy attained is somewhat less than machine precision but the error should not exceed more than 1 or 2 decimal places. Note also that there is a limit of 18 decimal places on the achievable accuracy, because constants in s14baf are given to this precision.

8
Parallelism and Performance

g01eff is not threaded in any implementation.

9
Further Comments

The time taken by g01eff varies slightly with the input arguments g, a and b.

10
Example

This example reads in values from a number of gamma distributions and computes the associated lower tail probabilities.

10.1
Program Text

Program Text (g01effe.f90)

10.2
Program Data

Program Data (g01effe.d)

10.3
Program Results

Program Results (g01effe.r)