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

# Syntax

C#
```public static void g01jc(
double[] a,
int[] mult,
double[] rlamda,
int n,
double c,
out double p,
out double pdf,
double tol,
int maxit,
out int ifail
)```
Visual Basic
```Public Shared Sub g01jc ( _
a As Double(), _
mult As Integer(), _
rlamda As Double(), _
n As Integer, _
c As Double, _
<OutAttribute> ByRef p As Double, _
<OutAttribute> ByRef pdf As Double, _
tol As Double, _
maxit As Integer, _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g01jc(
array<double>^ a,
array<int>^ mult,
array<double>^ rlamda,
int n,
double c,
[OutAttribute] double% p,
[OutAttribute] double% pdf,
double tol,
int maxit,
[OutAttribute] int% ifail
)```
F#
```static member g01jc :
a : float[] *
mult : int[] *
rlamda : float[] *
n : int *
c : float *
p : float byref *
pdf : float byref *
tol : float *
maxit : int *
ifail : int byref -> unit
```

#### Parameters

a
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: the weights, ${a}_{1},{a}_{2},\dots ,{a}_{n}$.
Constraint: ${\mathbf{a}}\left[\mathit{i}\right]>0.0$, for $\mathit{i}=0,1,\dots ,n-1$.
mult
Type: array<System..::..Int32>[]()[][]
An array of size [n]
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}=0,1,\dots ,{\mathbf{n}}-1$.
rlamda
Type: array<System..::..Double>[]()[][]
An array of size [n]
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}=0,1,\dots ,n-1$.
n
Type: System..::..Int32
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$.
c
Type: System..::..Double
On entry: $c$, the point for which the lower tail probability is to be evaluated.
Constraint: ${\mathbf{c}}\ge 0.0$.
p
Type: System..::..Double%
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$.
pdf
Type: System..::..Double%
On exit: the value of the probability density function of the linear combination of ${\chi }^{2}$ variables.
tol
Type: System..::..Double
On entry: the relative accuracy required by you in the results. If g01jc is entered with tol greater than or equal to $1.0$ or less than  (see x02aj), then the value of  is used instead.
maxit
Type: System..::..Int32
On entry: the maximum number of terms that should be used during the summation.
Suggested value: $500$.
Constraint: ${\mathbf{maxit}}\ge 1$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# 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∞dkFm+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$.

# References

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

# Error Indicators and Warnings

Note: g01jc may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the method:
If on exit ${\mathbf{ifail}}={1}$ or ${2}$, then g01jc 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}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

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

None.

None.

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

Example program (C#): g01jce.cs

Example program data: g01jce.d

Example program results: g01jce.r