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_noncentral (g01gc)

## Purpose

nag_stat_prob_chisq_noncentral (g01gc) returns the probability associated with the lower tail of the noncentral χ2${\chi }^{2}$-distribution via the function name.

## Syntax

[result, ifail] = g01gc(x, df, rlamda, 'tol', tol, 'maxit', maxit)
[result, ifail] = nag_stat_prob_chisq_noncentral(x, df, rlamda, 'tol', tol, 'maxit', maxit)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 23: tol now optional (default 0)
.

## Description

The lower tail probability of the noncentral χ2${\chi }^{2}$-distribution with ν$\nu$ degrees of freedom and noncentrality parameter λ$\lambda$, P(Xx : ν;λ)$P\left(X\le x:\nu \text{;}\lambda \right)$, is defined by
 ∞ P(X ≤ x : ν;λ) = ∑ e − λ / 2((λ / 2)j)/(j ! )P(X ≤ x : ν + 2j;0), j = 0
$P(X≤x:ν;λ)=∑j=0∞e-λ/2(λ/2)jj! P(X≤x:ν+2j;0),$
(1)
where P(Xx : ν + 2j;0)$P\left(X\le x:\nu +2j\text{;}0\right)$ is a central χ2${\chi }^{2}$-distribution with ν + 2j$\nu +2j$ degrees of freedom.
The value of j$j$ at which the Poisson weight, eλ / 2((λ / 2)j)/(j ! ) ${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$j$.
The recursive relationship:
 P(X ≤ x : a + 2;0) = P(X ≤ x : a;0) − ((xa / 2)e − x / 2)/(Γ(a + 1)) $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).

## References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications

## Parameters

### Compulsory Input Parameters

1:     x – double scalar
The deviate from the noncentral χ2${\chi }^{2}$-distribution with ν$\nu$ degrees of freedom and noncentrality parameter λ$\lambda$.
Constraint: x0.0${\mathbf{x}}\ge 0.0$.
2:     df – double scalar
ν$\nu$, the degrees of freedom of the noncentral χ2${\chi }^{2}$-distribution.
Constraint: df0.0${\mathbf{df}}\ge 0.0$.
3:     rlamda – double scalar
λ$\lambda$, the noncentrality parameter of the noncentral χ2${\chi }^{2}$-distribution.
Constraint: rlamda0.0${\mathbf{rlamda}}\ge 0.0$ if df > 0.0${\mathbf{df}}>0.0$ or rlamda > 0.0${\mathbf{rlamda}}>0.0$ if df = 0.0${\mathbf{df}}=0.0$.

### Optional Input Parameters

1:     tol – double scalar
The required accuracy of the solution. If nag_stat_prob_chisq_noncentral (g01gc) is entered with tol greater than or equal to 1.0$1.0$ or less than 10 × machine precision (see nag_machine_precision (x02aj)), then the value of 10 × machine precision is used instead.
Default: 0.0$0.0$
2:     maxit – int64int32nag_int scalar
The maximum number of iterations to be performed.
Default: 100$100$. See Section [Further Comments] for further discussion.
Constraint: maxit1${\mathbf{maxit}}\ge 1$.

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_noncentral (g01gc) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:
If on exit ${\mathbf{ifail}}={\mathbf{1}}$, 2${\mathbf{2}}$, 4${\mathbf{4}}$ or 5${\mathbf{5}}$, then nag_stat_prob_chisq_noncentral (g01gc) returns 0.0$0.0$.
ifail = 1${\mathbf{ifail}}=1$
 On entry, df < 0.0${\mathbf{df}}<0.0$, or rlamda < 0.0${\mathbf{rlamda}}<0.0$, or df = 0.0${\mathbf{df}}=0.0$ and rlamda = 0.0${\mathbf{rlamda}}=0.0$, or x < 0.0${\mathbf{x}}<0.0$, or maxit < 1${\mathbf{maxit}}<1$.
ifail = 2${\mathbf{ifail}}=2$
The initial value of the Poisson weight used in the summation (1) was too small to be calculated. The value of P(xx : ν;λ)$P\left({\mathbf{x}}\le x:\nu \text{;}\lambda \right)$ is likely to be zero.
ifail = 3${\mathbf{ifail}}=3$
The solution has failed to converge in maxit iterations.
ifail = 4${\mathbf{ifail}}=4$
The value of a term required in (2) is too large to be evaluated accurately. The most likely cause of this error is both x and rlamda being very large.
ifail = 5${\mathbf{ifail}}=5$
The calculations for the central χ2${\chi }^{2}$ probability has failed to converge. This is an unlikely error exit. A larger value of tol should be used.

## Accuracy

The summations described in Section [Description] are made until an upper bound on the truncation error relative to the current summation value is less than tol.

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

## Example

```function nag_stat_prob_chisq_noncentral_example
x = 8.26;
df = 20;
rlamda = 3.5;
[result, ifail] = nag_stat_prob_chisq_noncentral(x, df, rlamda)
```
```

result =

0.0032

ifail =

0

```
```function g01gc_example
x = 8.26;
df = 20;
rlamda = 3.5;
[result, ifail] = g01gc(x, df, rlamda)
```
```

result =

0.0032

ifail =

0

```