# NAG CL Interfaceg01jdc (prob_​chisq_​lincomb)

Settings help

CL Name Style:

## 1Purpose

g01jdc calculates the lower tail probability for a linear combination of (central) ${\chi }^{2}$ variables.

## 2Specification

 #include
 void g01jdc (Nag_LCCMethod method, Integer n, const double rlam[], double d, double c, double *prob, NagError *fail)
The function may be called by the names: g01jdc, nag_stat_prob_chisq_lincomb or nag_prob_lin_chi_sq.

## 3Description

Let ${u}_{1},{u}_{2},\dots ,{u}_{n}$ be independent Normal variables with mean zero and unit variance, so that ${u}_{1}^{2},{u}_{2}^{2},\dots ,{u}_{n}^{2}$ have independent ${\chi }^{2}$-distributions with unit degrees of freedom. g01jdc evaluates the probability that
 $λ1u12+λ2u22+⋯+λnun2
If $c=0.0$ this is equivalent to the probability that
 $λ1u12+λ2u22+⋯+λnun2 u12+u22+⋯+un2
Alternatively let
 $λi*=λi-d, ​ i= 1,2,…,n,$
then g01jdc returns the probability that
 $λ1*u12+λ2*u22+⋯+λn*un2
Two methods are available. One due to Pan (1964) (see Farebrother (1980)) makes use of series approximations. The other method due to Imhof (1961) reduces the problem to a one-dimensional integral. If $n\ge 6$ then a non-adaptive method is used to compute the value of the integral otherwise d01sjc is used.
Pan's procedure can only be used if the ${\lambda }_{i}^{*}$ are sufficiently distinct; g01jdc requires the ${\lambda }_{i}^{*}$ to be at least $1%$ distinct; see Section 9. If the ${\lambda }_{i}^{*}$ are at least $1%$ distinct and $n\le 60$, then Pan's procedure is recommended; otherwise Imhof's procedure is recommended.

## 4References

Farebrother R W (1980) Algorithm AS 153. Pan's procedure for the tail probabilities of the Durbin–Watson statistic Appl. Statist. 29 224–227
Imhof J P (1961) Computing the distribution of quadratic forms in Normal variables Biometrika 48 419–426
Pan Jie–Jian (1964) Distributions of the noncircular serial correlation coefficients Shuxue Jinzhan 7 328–337

## 5Arguments

1: $\mathbf{method}$Nag_LCCMethod Input
On entry: indicates whether Pan's, Imhof's or an appropriately selected procedure is to be used.
${\mathbf{method}}=\mathrm{Nag_LCCPan}$
Pan's method is used.
${\mathbf{method}}=\mathrm{Nag_LCCImhof}$
Imhof's method is used.
${\mathbf{method}}=\mathrm{Nag_LCCDefault}$
Pan's method is used if ${\lambda }_{\mathit{i}}^{*}$, for $\mathit{i}=1,2,\dots ,n$ are at least $1%$ distinct and $n\le 60$; otherwise Imhof's method is used.
Constraint: ${\mathbf{method}}=\mathrm{Nag_LCCPan}$, $\mathrm{Nag_LCCImhof}$ or $\mathrm{Nag_LCCDefault}$.
2: $\mathbf{n}$Integer Input
On entry: $n$, the number of independent standard Normal variates, (central ${\chi }^{2}$ variates).
Constraint: ${\mathbf{n}}\ge 1$.
3: $\mathbf{rlam}\left[{\mathbf{n}}\right]$const double Input
On entry: the weights, ${\lambda }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, of the central ${\chi }^{2}$ variables.
Constraint: ${\mathbf{rlam}}\left[\mathit{i}-1\right]\ne {\mathbf{d}}$ for at least one $\mathit{i}$. If ${\mathbf{method}}=\mathrm{Nag_LCCPan}$, the ${\lambda }_{\mathit{i}}^{*}$ must be at least $1%$ distinct; see Section 9, for $\mathit{i}=1,2,\dots ,n$.
4: $\mathbf{d}$double Input
On entry: $d$, the multiplier of the central ${\chi }^{2}$ variables.
Constraint: ${\mathbf{d}}\ge 0.0$.
5: $\mathbf{c}$double Input
On entry: $c$, the value of the constant.
6: $\mathbf{prob}$double * Output
On exit: the lower tail probability for the linear combination of central ${\chi }^{2}$ variables.
7: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_INT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\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.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_REAL
On entry, ${\mathbf{d}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{d}}\ge 0.0$.
NE_REAL_ARRAY
On entry, ${\mathbf{rlam}}\left[\mathit{i}-1\right]={\mathbf{d}}$ for all values of $\mathit{i}$, for $\mathit{i}=1,2,\dots ,n$.
NE_REAL_ARRAY_ENUM
On entry, ${\mathbf{method}}=\mathrm{Nag_LCCPan}$ but two successive values of $\lambda *$ were not $1$ percent distinct.

## 7Accuracy

On successful exit at least four decimal places of accuracy should be achieved.

## 8Parallelism and Performance

g01jdc is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

Pan's procedure can only work if the ${\lambda }_{i}^{*}$ are sufficiently distinct. g01jdc uses the check $|{w}_{j}-{w}_{j-1}|\ge 0.01×\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(|{w}_{j}|,|{w}_{j-1}|\right)$, where the ${w}_{j}$ are the ordered nonzero values of ${\lambda }_{i}^{*}$.
For the situation when all the ${\lambda }_{i}$ are positive g01jcc may be used. If the probabilities required are for the Durbin–Watson test, then the bounds for the probabilities are given by g01epc.

## 10Example

For $n=10$, the choice of method, values of $c$ and $d$ and the ${\lambda }_{i}$ are input and the probabilities computed and printed.

### 10.1Program Text

Program Text (g01jdce.c)

### 10.2Program Data

Program Data (g01jdce.d)

### 10.3Program Results

Program Results (g01jdce.r)