G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG01GCF

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

G01GCF returns the probability associated with the lower tail of the noncentral ${\chi }^{2}$-distribution via the routine name.

## 2  Specification

 FUNCTION G01GCF ( X, DF, RLAMDA, TOL, MAXIT, IFAIL)
 REAL (KIND=nag_wp) G01GCF
 INTEGER MAXIT, IFAIL REAL (KIND=nag_wp) X, DF, RLAMDA, TOL

## 3  Description

The lower tail probability of the noncentral ${\chi }^{2}$-distribution with $\nu$ degrees of freedom and noncentrality parameter $\lambda$, $P\left(X\le x:\nu \text{;}\lambda \right)$, is defined by
 $PX≤x:ν;λ=∑j=0∞e-λ/2λ/2jj! PX≤x:ν+2j;0,$ (1)
where $P\left(X\le x:\nu +2j\text{;}0\right)$ is a central ${\chi }^{2}$-distribution with $\nu +2j$ degrees of freedom.
The value of $j$ at which the Poisson weight, ${e}^{-\lambda /2}\frac{{\left(\lambda /2\right)}^{j}}{j!}$, is greatest is determined and the summation (1) is made forward and backward from that value of $j$.
The recursive relationship:
 $PX≤x:a+2;0=PX≤x:a;0-xa/2e-x/2 Γa+1$ (2)
is used during the summation in (1).

## 4  References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications

## 5  Parameters

1:     X – REAL (KIND=nag_wp)Input
On entry: the deviate from the noncentral ${\chi }^{2}$-distribution with $\nu$ degrees of freedom and noncentrality parameter $\lambda$.
Constraint: ${\mathbf{X}}\ge 0.0$.
2:     DF – REAL (KIND=nag_wp)Input
On entry: $\nu$, the degrees of freedom of the noncentral ${\chi }^{2}$-distribution.
Constraint: ${\mathbf{DF}}\ge 0.0$.
3:     RLAMDA – REAL (KIND=nag_wp)Input
On entry: $\lambda$, the noncentrality parameter of the noncentral ${\chi }^{2}$-distribution.
Constraint: ${\mathbf{RLAMDA}}\ge 0.0$ if ${\mathbf{DF}}>0.0$ or ${\mathbf{RLAMDA}}>0.0$ if ${\mathbf{DF}}=0.0$.
4:     TOL – REAL (KIND=nag_wp)Input
On entry: the required accuracy of the solution. If G01GCF is entered with TOL greater than or equal to $1.0$ or less than  (see X02AJF), then the value of  is used instead.
5:     MAXIT – INTEGERInput
On entry: the maximum number of iterations to be performed.
Suggested value: $100$. See Section 8 for further discussion.
Constraint: ${\mathbf{MAXIT}}\ge 1$.
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, 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: G01GCF 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}}$, ${\mathbf{2}}$, ${\mathbf{4}}$ or ${\mathbf{5}}$, then G01GCF returns $0.0$.
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{DF}}<0.0$, or ${\mathbf{RLAMDA}}<0.0$, or ${\mathbf{DF}}=0.0$ and ${\mathbf{RLAMDA}}=0.0$, or ${\mathbf{X}}<0.0$, or ${\mathbf{MAXIT}}<1$.
${\mathbf{IFAIL}}=2$
The initial value of the Poisson weight used in the summation (1) was too small to be calculated. The value of $P\left({\mathbf{X}}\le x:\nu \text{;}\lambda \right)$ is likely to be zero.
${\mathbf{IFAIL}}=3$
The solution has failed to converge in MAXIT iterations.
${\mathbf{IFAIL}}=4$
The value of a term required in (2) is too large to be evaluated accurately. The most likely cause of this error is both X and RLAMDA being very large.
${\mathbf{IFAIL}}=5$
The calculations for the central ${\chi }^{2}$ probability has failed to converge. This is an unlikely error exit. A larger value of TOL should be used.

## 7  Accuracy

The summations described in Section 3 are made until an upper bound on the truncation error relative to the current summation value is less than TOL.

The number of terms in (1) required for a given accuracy will depend on the following factors:
 (i) The rate at which the Poisson weights tend to zero. This will be slower for larger values of $\lambda$. (ii) The rate at which the central ${\chi }^{2}$ probabilities tend to zero. This will be slower for larger values of $\nu$ and $x$.

## 9  Example

This example reads values from various noncentral ${\chi }^{2}$-distributions, calculates the lower tail probabilities and prints all these values until the end of data is reached.

### 9.1  Program Text

Program Text (g01gcfe.f90)

### 9.2  Program Data

Program Data (g01gcfe.d)

### 9.3  Program Results

Program Results (g01gcfe.r)