# NAG Library Routine Document

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine g01jdf ( n, rlam, d, c, prob, work,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: rlam(n), d, c Real (Kind=nag_wp), Intent (Out) :: prob, work(n+1) Character (1), Intent (In) :: method
#include nagmk26.h
 void g01jdf_ (const char *method, const Integer *n, const double rlam[], const double *d, const double *c, double *prob, double work[], Integer *ifail, const Charlen length_method)

## 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. g01jdf 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 g01jdf 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 described in d01bdf is used to compute the value of the integral otherwise d01ajf is used.
Pan's procedure can only be used if the ${\lambda }_{i}^{*}$ are sufficiently distinct; g01jdf 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.
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}$ – Character(1)Input
On entry: indicates whether Pan's, Imhof's or an appropriately selected procedure is to be used.
${\mathbf{method}}=\text{'P'}$
Pan's method is used.
${\mathbf{method}}=\text{'I'}$
Imhof's method is used.
${\mathbf{method}}=\text{'D'}$
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}}=\text{'P'}$, $\text{'I'}$ or $\text{'D'}$.
2:     $\mathbf{n}$ – IntegerInput
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)$ – Real (Kind=nag_wp) arrayInput
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}\right)\ne {\mathbf{d}}$ for at least one $\mathit{i}$. If ${\mathbf{method}}=\text{'P'}$, the ${\lambda }_{\mathit{i}}^{*}$ must be at least $1%$ distinct; see Section 9, for $\mathit{i}=1,2,\dots ,n$.
4:     $\mathbf{d}$ – Real (Kind=nag_wp)Input
On entry: $d$, the multiplier of the central ${\chi }^{2}$ variables.
Constraint: ${\mathbf{d}}\ge 0.0$.
5:     $\mathbf{c}$ – Real (Kind=nag_wp)Input
On entry: $c$, the value of the constant.
6:     $\mathbf{prob}$ – Real (Kind=nag_wp)Output
On exit: the lower tail probability for the linear combination of central ${\chi }^{2}$ variables.
7:     $\mathbf{work}\left({\mathbf{n}}+1\right)$ – Real (Kind=nag_wp) arrayWorkspace
8:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{d}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{d}}\ge 0.0$.
On entry, ${\mathbf{method}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{method}}=\text{'P'}$, $\text{'I'}$ or $\text{'D'}$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{rlam}}\left(\mathit{i}\right)={\mathbf{d}}$ for all values of $\mathit{i}$, for $\mathit{i}=1,2,\dots ,n$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{method}}=\text{'P'}$ but two successive values of $\lambda *$ were not $1$ percent distinct.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

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

## 8Parallelism and Performance

g01jdf 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 routine. 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. g01jdf uses the check $\left|{w}_{j}-{w}_{j-1}\right|\ge 0.01×\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(\left|{w}_{j}\right|,\left|{w}_{j-1}\right|\right)$, where the ${w}_{j}$ are the ordered nonzero values of ${\lambda }_{i}^{*}$.
For the situation when all the ${\lambda }_{i}$ are positive g01jcf may be used. If the probabilities required are for the Durbin–Watson test, then the bounds for the probabilities are given by g01epf.

## 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 (g01jdfe.f90)

### 10.2Program Data

Program Data (g01jdfe.d)

### 10.3Program Results

Program Results (g01jdfe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017