G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG01GEF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G01GEF returns the probability associated with the lower tail of the noncentral beta distribution, via the routine name.

## 2  Specification

 FUNCTION G01GEF ( X, A, B, RLAMDA, TOL, MAXIT, IFAIL)
 REAL (KIND=nag_wp) G01GEF
 INTEGER MAXIT, IFAIL REAL (KIND=nag_wp) X, A, B, RLAMDA, TOL

## 3  Description

The lower tail probability for the noncentral beta distribution with parameters $a$ and $b$ and noncentrality parameter $\lambda$, $P\left(B\le \beta :a,b\text{;}\lambda \right)$, is defined by
 $PB≤β:a,b;λ=∑j=0∞e-λ/2 λ/2 j! PB≤β:a,b;0,$ (1)
where
 $PB≤β : a,b;0=Γ a+b Γ aΓ b ∫0βBa- 11-Bb- 1dB,$
which is the central beta probability function or incomplete beta function.
Recurrence relationships given in Abramowitz and Stegun (1972) are used to compute the values of $P\left(B\le \beta :a,b\text{;}0\right)$ for each step of the summation (1).
The algorithm is discussed in Lenth (1987).

## 4  References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Lenth R V (1987) Algorithm AS 226: Computing noncentral beta probabilities Appl. Statist. 36 241–244

## 5  Parameters

1:     X – REAL (KIND=nag_wp)Input
On entry: $\beta$, the deviate from the beta distribution, for which the probability $P\left(B\le \beta :a,b\text{;}\lambda \right)$ is to be found.
Constraint: $0.0\le {\mathbf{X}}\le 1.0$.
2:     A – REAL (KIND=nag_wp)Input
On entry: $a$, the first parameter of the required beta distribution.
Constraint: $0.0<{\mathbf{A}}\le {10}^{6}$.
3:     B – REAL (KIND=nag_wp)Input
On entry: $b$, the second parameter of the required beta distribution.
Constraint: $0.0<{\mathbf{B}}\le {10}^{6}$.
4:     RLAMDA – REAL (KIND=nag_wp)Input
On entry: $\lambda$, the noncentrality parameter of the required beta distribution.
Constraint: $0.0\le {\mathbf{RLAMDA}}\le -2.0\mathrm{log}\left(U\right)$, where $U$ is the safe range parameter as defined by X02AMF.
5:     TOL – REAL (KIND=nag_wp)Input
On entry: the relative accuracy required by you in the results. If G01GEF is entered with TOL greater than or equal to $1.0$ or less than  (see X02AJF), then the value of  is used instead.
See Section 7 for the relationship between TOL and MAXIT.
6:     MAXIT – INTEGERInput
On entry: the maximum number of iterations that the algorithm should use.
See Section 7 for suggestions as to suitable values for MAXIT for different values of the parameters.
Suggested value: $500$.
Constraint: ${\mathbf{MAXIT}}\ge 1$.
7:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if ${\mathbf{IFAIL}}\ne {\mathbf{0}}$ on exit, the recommended value is $-1$. When the value $-\mathbf{1}\text{​ or ​}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).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Note: G01GEF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{A}}\le 0.0$, or ${\mathbf{A}}>{10}^{6}$, or ${\mathbf{B}}\le 0.0$, or ${\mathbf{B}}>{10}^{6}$, or ${\mathbf{RLAMDA}}<0.0$, or ${\mathbf{RLAMDA}}>-2.0\mathrm{log}\left(U\right)$, where $U=\text{}$ safe range parameter as defined by X02AMF, or ${\mathbf{X}}<0.0$, or ${\mathbf{X}}>1.0$, or ${\mathbf{MAXIT}}<1$.
If on exit ${\mathbf{IFAIL}}={\mathbf{1}}$ then G01GEF returns zero.
${\mathbf{IFAIL}}=2$
The solution has failed to converge in MAXIT iterations. You should try a larger value of MAXIT or TOL. The returned value will be an approximation to the correct value.
${\mathbf{IFAIL}}=3$
The probability is too close to $0.0$ or $1.0$ for the algorithm to be able to calculate the required probability. G01GEF will return $0.0$ or $1.0$ as appropriate, this should be a reasonable approximation.
${\mathbf{IFAIL}}=4$
The required accuracy was not achieved when calculating the initial value of $P\left(B\le \beta :a,b\text{;}\lambda \right)$. You should try a larger value of TOL. The returned value will be an approximation to the correct value.

## 7  Accuracy

Convergence is theoretically guaranteed whenever $P\left(Y>{\mathbf{MAXIT}}\right)\le {\mathbf{TOL}}$ where $Y$ has a Poisson distribution with mean $\lambda /2$. Excessive round-off errors are possible when the number of iterations used is high and TOL is close to machine precision. See Lenth (1987) for further comments on the error bound.

The central beta probabilities can be obtained by setting ${\mathbf{RLAMDA}}=0.0$.

## 9  Example

This example reads values for several beta distributions and calculates and prints the lower tail probabilities until the end of data is reached.

### 9.1  Program Text

Program Text (g01gefe.f90)

### 9.2  Program Data

Program Data (g01gefe.d)

### 9.3  Program Results

Program Results (g01gefe.r)