# NAG Library Function Document

## 1Purpose

nag_gamma_dist (g01efc) returns the lower or upper tail probability of the gamma distribution, with parameters $\alpha$ and $\beta$.

## 2Specification

 #include #include
 double nag_gamma_dist (Nag_TailProbability tail, double g, double a, double b, NagError *fail)

## 3Description

The lower tail probability for the gamma distribution with parameters $\alpha$ and $\beta$, $P\left(G\le g\right)$, is defined by:
 $P G≤g ; α,β = 1 βα Γα ∫0g Gα-1 e-G/β dG , α>0.0 , ​ β>0.0 .$
The mean of the distribution is $\alpha \beta$ and its variance is $\alpha {\beta }^{2}$. The transformation $Z=\frac{G}{\beta }$ is applied to yield the following incomplete gamma function in normalized form,
 $P G≤g ; α ,β = P Z≤g/β : α,1.0 = 1 Γα ∫0g/β Zα-1 e-Z dZ .$
This is then evaluated using nag_incomplete_gamma (s14bac).

## 4References

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

## 5Arguments

1:    $\mathbf{tail}$Nag_TailProbabilityInput
On entry: indicates whether an upper or lower tail probability is required.
${\mathbf{tail}}=\mathrm{Nag_LowerTail}$
The lower tail probability is returned, that is $P\left(G\le g:\alpha ,\beta \right)$.
${\mathbf{tail}}=\mathrm{Nag_UpperTail}$
The upper tail probability is returned, that is $P\left(G\ge g:\alpha ,\beta \right)$.
Constraint: ${\mathbf{tail}}=\mathrm{Nag_LowerTail}$ or $\mathrm{Nag_UpperTail}$.
2:    $\mathbf{g}$doubleInput
On entry: $g$, the value of the gamma variate.
Constraint: ${\mathbf{g}}\ge 0.0$.
3:    $\mathbf{a}$doubleInput
On entry: the parameter $\alpha$ of the gamma distribution.
Constraint: ${\mathbf{a}}>0.0$.
4:    $\mathbf{b}$doubleInput
On entry: the parameter $\beta$ of the gamma distribution.
Constraint: ${\mathbf{b}}>0.0$.
5:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

On any of the error conditions listed below except ${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_ALG_NOT_CONV nag_gamma_dist (g01efc) returns $0.0$.
NE_ALG_NOT_CONV
The algorithm has failed to converge in $〈\mathit{\text{value}}〉$ iterations. The probability returned should be a reasonable approximation to the solution.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_REAL_ARG_LE
On entry, ${\mathbf{a}}=〈\mathit{\text{value}}〉$ and ${\mathbf{b}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{a}}>0.0$ and ${\mathbf{b}}>0.0$.
NE_REAL_ARG_LT
On entry, ${\mathbf{g}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{g}}\ge 0.0$.

## 7Accuracy

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 nag_incomplete_gamma (s14bac) are given to this precision.

## 8Parallelism and Performance

nag_gamma_dist (g01efc) is not threaded in any implementation.

The time taken by nag_gamma_dist (g01efc) varies slightly with the input arguments g, a and b.

## 10Example

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

### 10.1Program Text

Program Text (g01efce.c)

### 10.2Program Data

Program Data (g01efce.d)

### 10.3Program Results

Program Results (g01efce.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017