# NAG CL Interfaceg01fcc (inv_​cdf_​chisq)

Settings help

CL Name Style:

## 1Purpose

g01fcc returns the deviate associated with the given lower tail probability of the ${\chi }^{2}$-distribution with real degrees of freedom.

## 2Specification

 #include
 double g01fcc (double p, double df, NagError *fail)
The function may be called by the names: g01fcc, nag_stat_inv_cdf_chisq or nag_deviates_chi_sq.

## 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
 $P(X≤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).
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}$double 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}$double Input
On entry: $\nu$, the degrees of freedom of the ${\chi }^{2}$-distribution.
Constraint: ${\mathbf{df}}>0.0$.
3: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

If ${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_GAM_NOT_CONV, NE_PROBAB_CLOSE_TO_TAIL, NE_REAL_ARG_GE, NE_REAL_ARG_LE or NE_REAL_ARG_LT on exit, then g01fcc returns $0.0$.
On any of the error conditions listed below except ${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_ALG_NOT_CONV g01fcc returns $0.0$.
NE_ALG_NOT_CONV
The algorithm has failed to converge in $⟨\mathit{\text{value}}⟩$ iterations. The result should be a reasonable approximation.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_GAM_NOT_CONV
The series used to calculate the gamma function has failed to converge. This is an unlikely error exit.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_PROBAB_CLOSE_TO_TAIL
The probability is too close to $0.0$ or $1.0$.
NE_REAL_ARG_GE
On entry, ${\mathbf{p}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{p}}<1.0$.
NE_REAL_ARG_LE
On entry, ${\mathbf{df}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{df}}>0.0$.
NE_REAL_ARG_LT
On entry, ${\mathbf{p}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{p}}\ge 0.0$.

## 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

g01fcc is not threaded in any implementation.

For higher accuracy the relationship described in Section 3 may be used and a direct call to g01ffc 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 (g01fcce.c)

### 10.2Program Data

Program Data (g01fcce.d)

### 10.3Program Results

Program Results (g01fcce.r)