Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_stat_inv_cdf_chisq (g01fc)

## Purpose

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

## Syntax

[result, ifail] = g01fc(p, df)
[result, ifail] = nag_stat_inv_cdf_chisq(p, df)

## Description

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).

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{p}$ – double scalar
$p$, the lower tail probability from the required ${\chi }^{2}$-distribution.
Constraint: $0.0\le {\mathbf{p}}<1.0$.
2:     $\mathrm{df}$ – double scalar
$\nu$, the degrees of freedom of the ${\chi }^{2}$-distribution.
Constraint: ${\mathbf{df}}>0.0$.

None.

### Output Parameters

1:     $\mathrm{result}$ – double scalar
The result of the function.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Note: nag_stat_inv_cdf_chisq (g01fc) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:
If ${\mathbf{ifail}}={\mathbf{1}}$, ${\mathbf{2}}$, ${\mathbf{3}}$ or ${\mathbf{5}}$ on exit, then nag_stat_inv_cdf_chisq (g01fc) returns $0.0$.

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

${\mathbf{ifail}}=1$
 On entry, ${\mathbf{p}}<0.0$, or ${\mathbf{p}}\ge 1.0$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{df}}\le 0.0$.
${\mathbf{ifail}}=3$
p is too close to $0$ or $1$ for the result to be calculated.
W  ${\mathbf{ifail}}=4$
The solution has failed to converge. 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$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

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

For higher accuracy the relationship described in Description may be used and a direct call to nag_stat_inv_cdf_gamma (g01ff) made.

## Example

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.
```function g01fc_example

fprintf('g01fc example results\n\n');

p    = [ 0.01;   0.428;   0.869];
df   = [20.00;   7.500;  45.000];

fprintf('      p      df       x\n');
for j = 1:numel(p);

[x, ifail] = g01fc( ...
p(j) , df(j));

fprintf('%9.3f%8.3f%8.3f\n', p(j), df(j), x);
end

```
```g01fc example results

p      df       x
0.010  20.000   8.260
0.428   7.500   6.201
0.869  45.000  55.738
```