S Chapter Contents
S Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentS14CCF

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

S14CCF computes values for the incomplete beta function ${I}_{x}\left(a,b\right)$ and its complement $1-{I}_{x}\left(a,b\right)$.

## 2  Specification

 SUBROUTINE S14CCF ( A, B, X, W, W1, IFAIL)
 INTEGER IFAIL REAL (KIND=nag_wp) A, B, X, W, W1

## 3  Description

S14CCF evaluates the incomplete beta function and its complement in the normalized form
 $Ixa,b = 1 Ba,b ∫ 0 x ta-1 1-t b-1 dt 1–Ix a,b = Iy b,a , where ​ y=1-x ,$
with
• $0\le x\le 1$,
• $a\ge 0$ and $b\ge 0$,
• and the beta function $B\left(a,b\right)$ is defined as $B\left(a,b\right)=\underset{0}{\overset{1}{\int }}{t}^{a-1}{\left(1-t\right)}^{b-1}dt=\frac{\Gamma \left(a\right)\Gamma \left(b\right)}{\Gamma \left(a+b\right)}$ where $\Gamma \left(y\right)$ is the gamma function.
Several methods are used to evaluate the functions depending on the arguments $a$, $b$ and $x$. The methods include Wise's asymptotic expansion (see Wise (1950)) when $a>b$, continued fraction derived by DiDonato and Morris (1992) when $a$, $b>1$, and power series when $b\le 1$ or $b×x\le 0.7$. When both $a$ and $b$ are large, specifically $a$, $b\ge 15$, the DiDonato and Morris (1992) asymptotic expansion is employed for greater efficiency.
Once either ${I}_{x}\left(a,b\right)$ or ${I}_{y}\left(b,a\right)$ is computed, the other is obtained by subtraction from $1$. In order to avoid loss of relative precision in this subtraction, the smaller of ${I}_{x}\left(a,b\right)$ and ${I}_{y}\left(b,a\right)$ is computed first.
S14CCF is derived from BRATIO in DiDonato and Morris (1992).

## 4  References

DiDonato A R and Morris A H (1992) Algorithm 708: Significant digit computation of the incomplete beta function ratios ACM Trans. Math. Software 18 360–373
Wise M E (1950) The incomplete beta function as a contour integral and a quickly converging series for its inverse Biometrika 37 208–218

## 5  Parameters

1:     A – REAL (KIND=nag_wp)Input
On entry: the argument $a$ of the function.
Constraint: ${\mathbf{A}}\ge 0.0$.
2:     B – REAL (KIND=nag_wp)Input
On entry: the argument $b$ of the function.
Constraints:
• ${\mathbf{B}}\ge 0.0$;
• either ${\mathbf{B}}\ne 0.0$ or ${\mathbf{A}}\ne 0.0$.
3:     X – REAL (KIND=nag_wp)Input
On entry: $x$, upper limit of integration.
Constraints:
• $0.0\le {\mathbf{X}}\le 1.0$;
• either ${\mathbf{X}}\ne 0.0$ or ${\mathbf{A}}\ne 0.0$;
• either $1-{\mathbf{X}}\ne 0.0$ or ${\mathbf{B}}\ne 0.0$.
4:     W – REAL (KIND=nag_wp)Output
On exit: the value of the incomplete beta function ${I}_{x}\left(a,b\right)$ evaluated from zero to $x$.
5:     W1 – REAL (KIND=nag_wp)Output
On exit: the value of the complement of the incomplete beta function $1-{I}_{x}\left(a,b\right)$, i.e., the incomplete beta function evaluated from $x$ to one.
6:     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, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ 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).

## 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).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
On entry, ${\mathbf{A}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{A}}\ge 0.0$.
On entry, ${\mathbf{B}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{B}}\ge 0.0$.
${\mathbf{IFAIL}}=2$
On entry, A and B were zero.
Constraint: A or B must be nonzero.
${\mathbf{IFAIL}}=3$
On entry, ${\mathbf{X}}=⟨\mathit{\text{value}}⟩$.
Constraint: $0.0\le {\mathbf{X}}\le 1.0$.
${\mathbf{IFAIL}}=4$
On entry, X and A were zero.
Constraint: X or A must be nonzero.
${\mathbf{IFAIL}}=5$
On entry, $1.0-{\mathbf{X}}$ and B were zero.
Constraint: $1.0-{\mathbf{X}}$ or B must be nonzero.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.

## 7  Accuracy

S14CCF is designed to maintain relative accuracy for all arguments. For very tiny results (of the order of machine precision or less) some relative accuracy may be lost – loss of three or four decimal places has been observed in experiments. For other arguments full relative accuracy may be expected.

None.

## 9  Example

This example reads values of the arguments $a$ and $b$ from a file, evaluates the function and its complement for $10$ different values of $x$ and prints the results.

### 9.1  Program Text

Program Text (s14ccfe.f90)

### 9.2  Program Data

Program Data (s14ccfe.d)

### 9.3  Program Results

Program Results (s14ccfe.r)