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_prob_chisq (g01ec)

Purpose

nag_stat_prob_chisq (g01ec) returns the lower or upper tail probability for the χ2${\chi }^{2}$-distribution with real degrees of freedom.

Syntax

[result, ifail] = g01ec(x, df, 'tail', tail)
[result, ifail] = nag_stat_prob_chisq(x, df, 'tail', tail)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 23: tail now optional (default 'l')
.

Description

The lower tail probability for the χ2${\chi }^{2}$-distribution with ν$\nu$ degrees of freedom, P(Xx : ν)$P\left(X\le x:\nu \right)$ is defined by:
 x P(X ≤ x : ν) = 1/(2ν / 2Γ(ν / 2)) ∫ Xν / 2 − 1e − X / 2dX,  x ≥ 0,ν > 0. 0.0
$P(X≤x:ν)=12ν/2Γ(ν/2) ∫0.0xXν/2-1e-X/2dX, x≥0,ν>0.$
To calculate P(Xx : ν)$P\left(X\le x:\nu \right)$ a transformation of a gamma distribution is employed, i.e., a χ2${\chi }^{2}$-distribution with ν$\nu$ degrees of freedom is equal to a gamma distribution with scale parameter 2$2$ and shape parameter ν / 2$\nu /2$.

References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth

Parameters

Compulsory Input Parameters

1:     x – double scalar
x$x$, the value of the χ2${\chi }^{2}$ variate with ν$\nu$ degrees of freedom.
Constraint: x0.0${\mathbf{x}}\ge 0.0$.
2:     df – double scalar
ν$\nu$, the degrees of freedom of the χ2${\chi }^{2}$-distribution.
Constraint: df > 0.0${\mathbf{df}}>0.0$.

Optional Input Parameters

1:     tail – string (length ≥ 1)
Indicates whether the upper or lower tail probability is required.
tail = 'L'${\mathbf{tail}}=\text{'L'}$
The lower tail probability is returned, i.e., P(Xx : ν)$P\left(X\le x:\nu \right)$.
tail = 'U'${\mathbf{tail}}=\text{'U'}$
The upper tail probability is returned, i.e., P(Xx : ν)$P\left(X\ge x:\nu \right)$.
Default: 'L'$\text{'L'}$
Constraint: tail = 'L'${\mathbf{tail}}=\text{'L'}$ or 'U'$\text{'U'}$.

None.

Output Parameters

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

Error Indicators and Warnings

Note: nag_stat_prob_chisq (g01ec) 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}}$, 2${\mathbf{2}}$ or 3${\mathbf{3}}$ on exit, then nag_stat_prob_chisq (g01ec) returns 0.0$0.0$.
ifail = 1${\mathbf{ifail}}=1$
 On entry, tail ≠ 'L'${\mathbf{tail}}\ne \text{'L'}$ or 'U'$\text{'U'}$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, x < 0.0${\mathbf{x}}<0.0$.
ifail = 3${\mathbf{ifail}}=3$
 On entry, df ≤ 0.0${\mathbf{df}}\le 0.0$.
ifail = 4${\mathbf{ifail}}=4$
The solution has failed to converge while calculating the gamma variate. The result returned should represent an approximation to the solution.

Accuracy

A relative accuracy of five significant figures is obtained in most cases.

For higher accuracy the transformation described in Section [Description] may be used with a direct call to nag_specfun_gamma_incomplete (s14ba).

Example

```function nag_stat_prob_chisq_example
tail = 'Lower';
x = 8.26;
df = 20;
[result, ifail] = nag_stat_prob_chisq(x, df)
```
```

result =

0.0100

ifail =

0

```
```function g01ec_example
tail = 'Lower';
x = 8.26;
df = 20;
[result, ifail] = g01ec(x, df)
```
```

result =

0.0100

ifail =

0

```