# NAG FL Interfaceg01gcf (prob_​chisq_​noncentral)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

g01gcf returns the probability associated with the lower tail of the noncentral ${\chi }^{2}$-distribution.

## 2Specification

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

## 3Description

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
 $P(X≤x:ν;λ)=∑j=0∞e-λ/2(λ/2)jj! P(X≤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:
 $P(X≤x:a+2;0)=P(X≤x:a;0)-(xa/2)e-x/2 Γ(a+1)$ (2)
is used during the summation in (1).

## 4References

NIST Digital Library of Mathematical Functions

## 5Arguments

1: $\mathbf{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: $\mathbf{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: $\mathbf{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: $\mathbf{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), the value of is used instead.
5: $\mathbf{maxit}$Integer Input
On entry: the maximum number of iterations to be performed.
Suggested value: $100$. See Section 9 for further discussion.
Constraint: ${\mathbf{maxit}}\ge 1$.
6: $\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 g01gcf may return useful information.
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}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{df}}\ge 0.0$.
On entry, ${\mathbf{df}}=0.0$ and ${\mathbf{rlamda}}=0.0$.
Constraint: ${\mathbf{rlamda}}>0.0$ if ${\mathbf{df}}=0.0$.
On entry, ${\mathbf{maxit}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{maxit}}\ge 1$.
On entry, ${\mathbf{rlamda}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{rlamda}}\ge 0.0$.
On entry, ${\mathbf{x}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{x}}\ge 0.0$.
${\mathbf{ifail}}=2$
The initial value of the Poisson weight used in the summation of (1) (see Section 3) was too small to be calculated. The computed probability is likely to be zero.
${\mathbf{ifail}}=3$
The solution has failed to converge in $⟨\mathit{\text{value}}⟩$ iterations. Consider increasing maxit or tol.
${\mathbf{ifail}}=4$
The value of a term required in (2) (see Section 3) is too large to be evaluated accurately. The most likely cause of this error is both x and rlamda are too large.
${\mathbf{ifail}}=5$
The calculations for the central chi-square probability has failed to converge. A larger value of tol should be used.
${\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 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.

## 8Parallelism and Performance

g01gcf is not threaded in any implementation.

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

## 10Example

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.

### 10.1Program Text

Program Text (g01gcfe.f90)

### 10.2Program Data

Program Data (g01gcfe.d)

### 10.3Program Results

Program Results (g01gcfe.r)