G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG01JCF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G01JCF returns the lower tail probability of a distribution of a positive linear combination of ${\chi }^{2}$ random variables.

## 2  Specification

 SUBROUTINE G01JCF ( A, MULT, RLAMDA, N, C, P, PDF, TOL, MAXIT, WRK, IFAIL)
 INTEGER MULT(N), N, MAXIT, IFAIL REAL (KIND=nag_wp) A(N), RLAMDA(N), C, P, PDF, TOL, WRK(N+2*MAXIT)

## 3  Description

For a linear combination of noncentral ${\chi }^{2}$ random variables with integer degrees of freedom the lower tail probability is
 $P ∑j=1najχ2mj,λj≤c ,$ (1)
where ${a}_{j}$ and $c$ are positive constants and where ${\chi }^{2}\left({m}_{j},{\lambda }_{j}\right)$ represents an independent ${\chi }^{2}$ random variable with ${m}_{j}$ degrees of freedom and noncentrality parameter ${\lambda }_{j}$. The linear combination may arise from considering a quadratic form in Normal variables.
Ruben's method as described in Farebrother (1984) is used. Ruben has shown that (1) may be expanded as an infinite series of the form
 $∑k=0∞dkF m+2k,c/β ,$ (2)
where $F\left(m+2k,c/\beta \right)=P\left({\chi }^{2}\left(m+2k\right), i.e., the probability that a central ${\chi }^{2}$ is less than $c/\beta$.
The value of $\beta$ is set at
 $β=βB=21/amin+1/amax$
unless ${\beta }_{B}>1.8{a}_{\mathrm{min}}$, in which case
 $β=βA=amin$
is used, where ${a}_{\mathrm{min}}=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left\{{a}_{j}\right\}$ and ${a}_{\mathrm{max}}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left\{{a}_{j}\right\}$, for $\mathit{j}=1,2,\dots ,n$.

## 4  References

Farebrother R W (1984) The distribution of a positive linear combination of ${\chi }^{2}$ random variables Appl. Statist. 33(3)

## 5  Parameters

1:     $\mathrm{A}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: the weights, ${a}_{1},{a}_{2},\dots ,{a}_{n}$.
Constraint: ${\mathbf{A}}\left(\mathit{i}\right)>0.0$, for $\mathit{i}=1,2,\dots ,n$.
2:     $\mathrm{MULT}\left({\mathbf{N}}\right)$ – INTEGER arrayInput
On entry: the degrees of freedom, ${m}_{1},{m}_{2},\dots ,{m}_{n}$.
Constraint: ${\mathbf{MULT}}\left(\mathit{i}\right)\ge 1$, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$.
3:     $\mathrm{RLAMDA}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: the noncentrality parameters, ${\lambda }_{1},{\lambda }_{2},\dots ,{\lambda }_{n}$.
Constraint: ${\mathbf{RLAMDA}}\left(\mathit{i}\right)\ge 0.0$, for $\mathit{i}=1,2,\dots ,n$.
4:     $\mathrm{N}$ – INTEGERInput
On entry: $n$, the number of ${\chi }^{2}$ random variables in the combination, i.e., the number of terms in equation (1).
Constraint: ${\mathbf{N}}\ge 1$.
5:     $\mathrm{C}$ – REAL (KIND=nag_wp)Input
On entry: $c$, the point for which the lower tail probability is to be evaluated.
Constraint: ${\mathbf{C}}\ge 0.0$.
6:     $\mathrm{P}$ – REAL (KIND=nag_wp)Output
On exit: the lower tail probability associated with the linear combination of $n$ ${\chi }^{2}$ random variables with ${m}_{\mathit{j}}$ degrees of freedom, and noncentrality parameters ${\lambda }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,n$.
7:     $\mathrm{PDF}$ – REAL (KIND=nag_wp)Output
On exit: the value of the probability density function of the linear combination of ${\chi }^{2}$ variables.
8:     $\mathrm{TOL}$ – REAL (KIND=nag_wp)Input
On entry: the relative accuracy required by you in the results. If G01JCF is entered with TOL greater than or equal to $1.0$ or less than  (see X02AJF), then the value of  is used instead.
9:     $\mathrm{MAXIT}$ – INTEGERInput
On entry: the maximum number of terms that should be used during the summation.
Suggested value: $500$.
Constraint: ${\mathbf{MAXIT}}\ge 1$.
10:   $\mathrm{WRK}\left({\mathbf{N}}+2×{\mathbf{MAXIT}}\right)$ – REAL (KIND=nag_wp) arrayWorkspace
11:   $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if ${\mathbf{IFAIL}}\ne {\mathbf{0}}$ on exit, the recommended value is $-1$. When the value $-\mathbf{1}\text{​ or ​}1$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Note: G01JCF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
If on exit ${\mathbf{IFAIL}}={\mathbf{1}}$ or ${\mathbf{2}}$, then G01JCF returns $0.0$.
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{N}}<1$, or ${\mathbf{MAXIT}}<1$, or ${\mathbf{C}}<0.0$.
${\mathbf{IFAIL}}=2$
 On entry, A has an element $\text{}\le 0.0$, or MULT has an element $\text{}<1$, or RLAMDA has an element $\text{}<0.0$.
${\mathbf{IFAIL}}=3$
The central ${\chi }^{2}$ calculation has failed to converge. This is an unlikely exit. A larger value of TOL should be tried.
${\mathbf{IFAIL}}=4$
The solution has failed to converge within MAXIT iterations. A larger value of MAXIT or TOL should be used. The returned value should be a reasonable approximation to the correct value.
${\mathbf{IFAIL}}=5$
The solution appears to be too close to $0$ or $1$ for accurate calculation. The value returned is $0$ or $1$ as appropriate.
${\mathbf{IFAIL}}=-99$
See Section 3.8 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

## 7  Accuracy

The series (2) is summed until a bound on the truncation error is less than TOL. See Farebrother (1984) for further discussion.

Not applicable.

None.

## 10  Example

The number of ${\chi }^{2}$ variables is read along with their coefficients, degrees of freedom and noncentrality parameters. The lower tail probability is then computed and printed.

### 10.1  Program Text

Program Text (g01jcfe.f90)

### 10.2  Program Data

Program Data (g01jcfe.d)

### 10.3  Program Results

Program Results (g01jcfe.r)