# NAG FL Interfaceg01eff (prob_​gamma)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

g01eff returns the lower or upper tail probability of the gamma distribution, with parameters $\alpha$ and $\beta$.

## 2Specification

Fortran Interface
 Function g01eff ( tail, g, a, b,
 Real (Kind=nag_wp) :: g01eff Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: g, a, b Character (1), Intent (In) :: tail
#include <nag.h>
 double g01eff_ (const char *tail, const double *g, const double *a, const double *b, Integer *ifail, const Charlen length_tail)
The routine may be called by the names g01eff or nagf_stat_prob_gamma.

## 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 s14baf.
Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth

## 5Arguments

1: $\mathbf{tail}$Character(1) Input
On entry: indicates whether an upper or lower tail probability is required.
${\mathbf{tail}}=\text{'L'}$
The lower tail probability is returned, that is $P\left(G\le g:\alpha ,\beta \right)$.
${\mathbf{tail}}=\text{'U'}$
The upper tail probability is returned, that is $P\left(G\ge g:\alpha ,\beta \right)$.
Constraint: ${\mathbf{tail}}=\text{'L'}$ or $\text{'U'}$.
2: $\mathbf{g}$Real (Kind=nag_wp) Input
On entry: $g$, the value of the gamma variate.
Constraint: ${\mathbf{g}}\ge 0.0$.
3: $\mathbf{a}$Real (Kind=nag_wp) Input
On entry: the parameter $\alpha$ of the gamma distribution.
Constraint: ${\mathbf{a}}>0.0$.
4: $\mathbf{b}$Real (Kind=nag_wp) Input
On entry: the parameter $\beta$ of the gamma distribution.
Constraint: ${\mathbf{b}}>0.0$.
5: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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 ${\mathbf{ifail}}={\mathbf{1}}$, ${\mathbf{2}}$, ${\mathbf{3}}$ or ${\mathbf{4}}$ on exit, then g01eff returns $0.0$.
${\mathbf{ifail}}=1$
On entry, ${\mathbf{tail}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{tail}}=\text{'L'}$ or $\text{'U'}$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{g}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{g}}\ge 0.0$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{a}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{b}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{a}}>0.0$ and ${\mathbf{b}}>0.0$.
${\mathbf{ifail}}=4$
The algorithm has failed to converge in $⟨\mathit{\text{value}}⟩$ iterations. The probability returned should be a reasonable approximation to the solution.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 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 s14baf are given to this precision.

## 8Parallelism and Performance

g01eff is not threaded in any implementation.

The time taken by g01eff 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 (g01effe.f90)

### 10.2Program Data

Program Data (g01effe.d)

### 10.3Program Results

Program Results (g01effe.r)