# NAG Library Routine Document

## 1Purpose

g01fcf returns the deviate associated with the given lower tail probability of the ${\chi }^{2}$-distribution with real degrees of freedom, via the routine name.

## 2Specification

Fortran Interface
 Function g01fcf ( p, df,
 Real (Kind=nag_wp) :: g01fcf Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: p, df
#include nagmk26.h
 double g01fcf_ (const double *p, const double *df, Integer *ifail)

## 3Description

The deviate, ${x}_{p}$, associated with the lower tail probability $p$ of the ${\chi }^{2}$-distribution with $\nu$ degrees of freedom is defined as the solution to
 $PX≤xp:ν=p=12ν/2Γν/2 ∫0xpe-X/2Xv/2-1dX, 0≤xp<∞;ν>0.$
The required ${x}_{p}$ is found by using the relationship between a ${\chi }^{2}$-distribution and a gamma distribution, i.e., a ${\chi }^{2}$-distribution with $\nu$ degrees of freedom is equal to a gamma distribution with scale parameter $2$ and shape parameter $\nu /2$.
For very large values of $\nu$, greater than ${10}^{5}$, Wilson and Hilferty's normal approximation to the ${\chi }^{2}$ is used; see Kendall and Stuart (1969).

## 4References

Best D J and Roberts D E (1975) Algorithm AS 91. The percentage points of the ${\chi }^{2}$ distribution Appl. Statist. 24 385–388
Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth
Kendall M G and Stuart A (1969) The Advanced Theory of Statistics (Volume 1) (3rd Edition) Griffin

## 5Arguments

1:     $\mathbf{p}$ – Real (Kind=nag_wp)Input
On entry: $p$, the lower tail probability from the required ${\chi }^{2}$-distribution.
Constraint: $0.0\le {\mathbf{p}}<1.0$.
2:     $\mathbf{df}$ – Real (Kind=nag_wp)Input
On entry: $\nu$, the degrees of freedom of the ${\chi }^{2}$-distribution.
Constraint: ${\mathbf{df}}>0.0$.
3:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 arguments 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).

## 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).
Note: g01fcf may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
If ${\mathbf{ifail}}={\mathbf{1}}$, ${\mathbf{2}}$, ${\mathbf{3}}$ or ${\mathbf{5}}$ on exit, then g01fcf returns $0.0$.
${\mathbf{ifail}}=1$
On entry, ${\mathbf{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{p}}\ge 0.0$.
On entry, ${\mathbf{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{p}}<1.0$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{df}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{df}}>0.0$.
${\mathbf{ifail}}=3$
The probability is too close to $0.0$ or $1.0$.
${\mathbf{ifail}}=4$
The algorithm has failed to converge in $〈\mathit{\text{value}}〉$ iterations. The result should be a reasonable approximation.
${\mathbf{ifail}}=5$
The series used to calculate the gamma function has failed to converge. This is an unlikely error exit.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

The results should be accurate to five significant digits for most argument values. Some accuracy is lost for $p$ close to $0.0$.

## 8Parallelism and Performance

g01fcf is not threaded in any implementation.

For higher accuracy the relationship described in Section 3 may be used and a direct call to g01fff made.

## 10Example

This example reads lower tail probabilities for several ${\chi }^{2}$-distributions, and calculates and prints the corresponding deviates until the end of data is reached.

### 10.1Program Text

Program Text (g01fcfe.f90)

### 10.2Program Data

Program Data (g01fcfe.d)

### 10.3Program Results

Program Results (g01fcfe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017