Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_stat_prob_gamma (g01ef)

## Purpose

nag_stat_prob_gamma (g01ef) returns the lower or upper tail probability of the gamma distribution, with parameters α$\alpha$ and β$\beta$.

## Syntax

[result, ifail] = g01ef(g, a, b, 'tail', tail)
[result, ifail] = nag_stat_prob_gamma(g, a, b, 'tail', tail)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 23: tail now optional (default 'l')
.

## Description

The lower tail probability for the gamma distribution with parameters α$\alpha$ and β$\beta$, P(Gg)$P\left(G\le g\right)$, is defined by:
 g P( G ≤ g ; α,β) = 1/( βα Γ(α) ) ∫ Gα − 1e − G / βdG,  α > 0.0, ​β > 0.0. 0
$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 αβ2$\alpha {\beta }^{2}$. The transformation Z = G/β$Z=\frac{G}{\beta }$ is applied to yield the following incomplete gamma function in normalized form,
 g / β P( G ≤ g ; α ,β) = P( Z ≤ g / β : α,1.0) = 1/(Γ(α)) ∫ Zα − 1e − ZdZ. 0
$P ( G≤g ; α ,β) = P ( Z≤g/β : α,1.0) = 1 Γ(α) ∫0g/β Zα-1 e-Z dZ .$
This is then evaluated using nag_specfun_gamma_incomplete (s14ba).

## References

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

## Parameters

### Compulsory Input Parameters

1:     g – double scalar
g$g$, the value of the gamma variate.
Constraint: g0.0${\mathbf{g}}\ge 0.0$.
2:     a – double scalar
The parameter α$\alpha$ of the gamma distribution.
Constraint: a > 0.0${\mathbf{a}}>0.0$.
3:     b – double scalar
The parameter β$\beta$ of the gamma distribution.
Constraint: b > 0.0${\mathbf{b}}>0.0$.

### Optional Input Parameters

1:     tail – string (length ≥ 1)
Indicates whether an upper or lower tail probability is required.
tail = 'L'${\mathbf{tail}}=\text{'L'}$
The lower tail probability is returned, that is P(Gg : α,β)$P\left(G\le g:\alpha ,\beta \right)$.
tail = 'U'${\mathbf{tail}}=\text{'U'}$
The upper tail probability is returned, that is P(Gg : α,β)$P\left(G\ge g:\alpha ,\beta \right)$.
Default: 'L'$\text{'L'}$
Constraint: tail = 'L'${\mathbf{tail}}=\text{'L'}$ or 'U'$\text{'U'}$.

None.

### Output Parameters

1:     result – double scalar
The result of the function.
2:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
If ${\mathbf{ifail}}={\mathbf{1}}$, 2${\mathbf{2}}$, 3${\mathbf{3}}$ or 4${\mathbf{4}}$ on exit, then nag_stat_prob_gamma (g01ef) returns 0.0$0.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 = 1${\mathbf{ifail}}=1$
 On entry, tail ≠ 'L'${\mathbf{tail}}\ne \text{'L'}$ or 'U'$\text{'U'}$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, g < 0.0${\mathbf{g}}<0.0$.
ifail = 3${\mathbf{ifail}}=3$
 On entry, a ≤ 0.0${\mathbf{a}}\le 0.0$, or b ≤ 0.0${\mathbf{b}}\le 0.0$.
W ifail = 4${\mathbf{ifail}}=4$
The solution did not converge in 600$600$ iterations. See nag_specfun_gamma_incomplete (s14ba). The probability returned should be a reasonable approximation to the solution.

## 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$1$ or 2$2$ decimal places. Note also that there is a limit of 18$18$ decimal places on the achievable accuracy, because constants in nag_specfun_gamma_incomplete (s14ba) are given to this precision.

The time taken by nag_stat_prob_gamma (g01ef) varies slightly with the input parameters g, a and b.

## Example

```function nag_stat_prob_gamma_example
g = 15.5;
a = 4;
b = 2;
[result, ifail] = nag_stat_prob_gamma(g, a, b)
```
```

result =

0.9499

ifail =

0

```
```function g01ef_example
g = 15.5;
a = 4;
b = 2;
[result, ifail] = g01ef(g, a, b)
```
```

result =

0.9499

ifail =

0

```