g01 Chapter Contents
g01 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_prob_non_central_chi_sq (g01gcc)

## 1  Purpose

nag_prob_non_central_chi_sq (g01gcc) returns the probability associated with the lower tail of the noncentral ${\chi }^{2}$-distribution .

## 2  Specification

 #include #include
 double nag_prob_non_central_chi_sq (double x, double df, double lambda, double tol, Integer max_iter, NagError *fail)

## 3  Description

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

## 4  References

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

## 5  Arguments

1:     xdoubleInput
On entry: the deviate from the noncentral ${\chi }^{2}$-distribution with $\nu$ degrees of freedom and noncentrality parameter $\lambda$.
Constraint: ${\mathbf{x}}\ge 0.0$.
2:     dfdoubleInput
On entry: $\nu$, the degrees of freedom of the noncentral ${\chi }^{2}$-distribution.
Constraint: ${\mathbf{df}}\ge 0.0$.
On entry: $\lambda$, the noncentrality parameter of the noncentral ${\chi }^{2}$-distribution.
Constraint: ${\mathbf{lambda}}\ge 0.0$ if ${\mathbf{df}}>0.0$ or ${\mathbf{lambda}}>0.0$ if ${\mathbf{df}}=0.0$.
4:     toldoubleInput
On entry: the required accuracy of the solution. If nag_prob_non_central_chi_sq (g01gcc) is entered with tol greater than or equal to $1.0$ or less than  (see nag_machine_precision (X02AJC)), then the value of  is used instead.
5:     max_iterIntegerInput
On entry: the maximum number of iterations to be performed.
Suggested value: $100$. See Section 8 for further discussion.
Constraint: ${\mathbf{max_iter}}\ge 1$.
6:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_2_REAL_ARG_CONS
On entry, ${\mathbf{df}}=0.0$ and ${\mathbf{lambda}}=0.0$.
Constraint: ${\mathbf{lambda}}>0.0$ if ${\mathbf{df}}=0.0$.
NE_CHI_PROB
The calculations for the central chi-square probability has failed to converge. A larger value of tol should be used.
NE_CONV
The solution has failed to converge in $〈\mathit{\text{value}}〉$ iterations. Consider increasing max_iter or tol.
NE_INT_ARG_LT
On entry, ${\mathbf{max_iter}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{max_iter}}\ge 1$.
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.
NE_POISSON_WEIGHT
The initial value of the Poisson weight used in the summation of (1) (see Section 3) was too small to be calculated. The computed probability is likely to be zero.
NE_REAL_ARG_LT
On entry, ${\mathbf{df}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{df}}\ge 0.0$.
On entry, ${\mathbf{lambda}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lambda}}\ge 0.0$.
On entry, ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{x}}\ge 0.0$.
NE_TERM_LARGE
The value of a term required in (2) (see Section 3) is too large to be evaluated accurately. The most likely cause of this error is both x and lambda are too large.

## 7  Accuracy

The summations described in Section 3 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 ${\chi }^{2}$ probabilities tend to zero. This will be slower for larger values of $\nu$ and $x$.

## 9  Example

This example reads values from various noncentral ${\chi }^{2}$-distributions, calculates the lower tail probabilities and prints all these values until the end of data is reached.

### 9.1  Program Text

Program Text (g01gcce.c)

### 9.2  Program Data

Program Data (g01gcce.d)

### 9.3  Program Results

Program Results (g01gcce.r)