G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG01FEF

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

G01FEF returns the deviate associated with the given lower tail probability of the beta distribution, via the routine name.

## 2  Specification

 FUNCTION G01FEF ( P, A, B, TOL, IFAIL)
 REAL (KIND=nag_wp) G01FEF
 INTEGER IFAIL REAL (KIND=nag_wp) P, A, B, TOL

## 3  Description

The deviate, ${\beta }_{p}$, associated with the lower tail probability, $p$, of the beta distribution with parameters $a$ and $b$ is defined as the solution to
 $PB≤βp:a,b=p=Γa+b ΓaΓb ∫0βpBa-11-Bb-1dB, 0≤βp≤1;a,b>0.$
The algorithm is a modified version of the Newton–Raphson method, following closely that of Cran et al. (1977).
An initial approximation, ${\beta }_{0}$, to ${\beta }_{p}$ is found (see Cran et al. (1977)), and the Newton–Raphson iteration
 $βi=βi-1-fβi-1 f′βi-1 ,$
where $f\left(\beta \right)=P\left(B\le \beta :a,b\right)-p$ is used, with modifications to ensure that $\beta$ remains in the range $\left(0,1\right)$.

## 4  References

Cran G W, Martin K J and Thomas G E (1977) Algorithm AS 109. Inverse of the incomplete beta function ratio Appl. Statist. 26 111–114
Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth

## 5  Parameters

1:     P – REAL (KIND=nag_wp)Input
On entry: $p$, the lower tail probability from the required beta distribution.
Constraint: $0.0\le {\mathbf{P}}\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:     TOL – REAL (KIND=nag_wp)Input
On entry: the relative accuracy required by you in the result. If G01FEF is entered with TOL greater than or equal to $1.0$ or less than  (see X02AJF), then the value of  is used instead.
5:     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: G01FEF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
If on exit ${\mathbf{IFAIL}}={\mathbf{1}}$ or ${\mathbf{2}}$, then G01FEF returns $0.0$.
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{P}}<0.0$, or ${\mathbf{P}}>1.0$.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{A}}\le 0.0$, or ${\mathbf{A}}>{10}^{6}$, or ${\mathbf{B}}\le 0.0$, or ${\mathbf{B}}>{10}^{6}$.
${\mathbf{IFAIL}}=3$
There is doubt concerning the accuracy of the computed result. $100$ iterations of the Newton–Raphson method have been performed without satisfying the accuracy criterion (see Section 7). The result should be a reasonable approximation of the solution.
${\mathbf{IFAIL}}=4$
Requested accuracy not achieved when calculating beta probability. The result should be a reasonable approximation to the correct solution. You should try setting TOL larger.

## 7  Accuracy

The required precision, given by TOL, should be achieved in most circumstances.

The typical timing will be several times that of G01EEF and will be very dependent on the input parameter values. See G01EEF for further comments on timings.

## 9  Example

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

### 9.1  Program Text

Program Text (g01fefe.f90)

### 9.2  Program Data

Program Data (g01fefe.d)

### 9.3  Program Results

Program Results (g01fefe.r)