# NAG FL Interfaceg01fef (inv_​cdf_​beta)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

g01fef returns the deviate associated with the given lower tail probability of the beta distribution.

## 2Specification

Fortran Interface
 Function g01fef ( p, a, b, tol,
 Real (Kind=nag_wp) :: g01fef Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: p, a, b, tol
#include <nag.h>
 double g01fef_ (const double *p, const double *a, const double *b, const double *tol, Integer *ifail)
The routine may be called by the names g01fef or nagf_stat_inv_cdf_beta.

## 3Description

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
 $P(B≤βp:a,b)=p=Γ(a+b) Γ(a)Γ(b) ∫0βpBa-1(1-B)b-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)$.

## 4References

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

## 5Arguments

1: $\mathbf{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: $\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{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), the value of is used instead.
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 $-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 g01fef may return useful information.
If on exit ${\mathbf{ifail}}={\mathbf{1}}$ or ${\mathbf{2}}$, then g01fef returns $0.0$.
${\mathbf{ifail}}=1$
On entry, ${\mathbf{p}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{p}}\le 1.0$.
On entry, ${\mathbf{p}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{p}}\ge 0.0$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{a}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{b}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{a}}>0.0$.
On entry, ${\mathbf{a}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{b}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{a}}\le {10}^{6}$.
On entry, ${\mathbf{a}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{b}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{b}}>0.0$.
On entry, ${\mathbf{a}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{b}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{b}}\le {10}^{6}$.
${\mathbf{ifail}}=3$
The solution has failed to converge. However, the result should be a reasonable approximation. Requested accuracy not achieved when calculating beta probability. You should try setting tol larger.
${\mathbf{ifail}}=4$
The requested accuracy has not been achieved. Use a larger value of tol. 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 9). The result should be a reasonable approximation of 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 required precision, given by tol, should be achieved in most circumstances.

## 8Parallelism and Performance

g01fef is not threaded in any implementation.

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

## 10Example

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

### 10.1Program Text

Program Text (g01fefe.f90)

### 10.2Program Data

Program Data (g01fefe.d)

### 10.3Program Results

Program Results (g01fefe.r)