# NAG FL Interfaceg01gef (prob_​beta_​noncentral)

## 1Purpose

g01gef returns the probability associated with the lower tail of the noncentral beta distribution.

## 2Specification

Fortran Interface
 Function g01gef ( x, a, b, tol,
 Real (Kind=nag_wp) :: g01gef Integer, Intent (In) :: maxit Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: x, a, b, rlamda, tol
#include <nag.h>
 double g01gef_ (const double *x, const double *a, const double *b, const double *rlamda, const double *tol, const Integer *maxit, Integer *ifail)
The routine may be called by the names g01gef or nagf_stat_prob_beta_noncentral.

## 3Description

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).

## 4References

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

## 5Arguments

1: $\mathbf{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: $\mathbf{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: $\mathbf{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: $\mathbf{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: $\mathbf{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), the value of is used instead.
See Section 7 for the relationship between tol and maxit.
6: $\mathbf{maxit}$Integer Input
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 arguments.
Suggested value: $500$.
Constraint: ${\mathbf{maxit}}\ge 1$.
7: $\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 $-1$ is recommended since useful values can be provided in some output arguments even when ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit. 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:
Note: in some cases g01gef may return useful information.
${\mathbf{ifail}}=1$
On entry, ${\mathbf{a}}=〈\mathit{\text{value}}〉$.
Constraint: $0.0<{\mathbf{a}}\le {10}^{6}$.
On entry, ${\mathbf{b}}=〈\mathit{\text{value}}〉$.
Constraint: $0.0<{\mathbf{b}}\le {10}^{6}$.
On entry, ${\mathbf{maxit}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{maxit}}\ge 1$.
On entry, ${\mathbf{rlamda}}=〈\mathit{\text{value}}〉$.
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.
On entry, ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
Constraint: $0.0\le {\mathbf{x}}\le 1.0$.
${\mathbf{ifail}}=2$
The solution has failed to converge in $〈\mathit{\text{value}}〉$ iterations. Consider increasing 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 the beta distribution. You should try a larger value of tol. The returned value will be an approximation to the correct value. This error exit is no longer possible but is still documented for historical reasons.
${\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

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.

## 8Parallelism and Performance

g01gef is not threaded in any implementation.

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

## 10Example

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

### 10.1Program Text

Program Text (g01gefe.f90)

### 10.2Program Data

Program Data (g01gefe.d)

### 10.3Program Results

Program Results (g01gefe.r)