Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_stat_prob_chisq_lincomb (g01jd)

## Purpose

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

## Syntax

[prob, ifail] = g01jd(rlam, d, c, 'method', method, 'n', n)
[prob, ifail] = nag_stat_prob_chisq_lincomb(rlam, d, c, 'method', method, 'n', n)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 23: method now optional (default d)
.

## Description

Let u1,u2,,un${u}_{1},{u}_{2},\dots ,{u}_{n}$ be independent Normal variables with mean zero and unit variance, so that u12,u22,,un2${u}_{1}^{2},{u}_{2}^{2},\dots ,{u}_{n}^{2}$ have independent χ2${\chi }^{2}$-distributions with unit degrees of freedom. nag_stat_prob_chisq_lincomb (g01jd) evaluates the probability that
 λ1u12 + λ2u22 + ⋯ + λnun2 < d(u12 + u22 + ⋯ + un2) + c. $λ1u12+λ2u22+⋯+λnun2
If c = 0.0$c=0.0$ this is equivalent to the probability that
 (λ1u12 + λ2u22 + ⋯ + λnun2)/(u12 + u22 + ⋯ + un2) < d. $λ1u12+λ2u22+⋯+λnun2 u12+u22+⋯+un2
Alternatively let
 λi * = λi − d,   ​ i = 1,2, … ,n, $λi*=λi-d, ​ i= 1,2,…,n,$
then nag_stat_prob_chisq_lincomb (g01jd) returns the probability that
 λ1 * u12 + λ2 * u22 + ⋯ + λn * un2 < c. $λ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 n6$n\ge 6$ then a non-adaptive method described in nag_quad_1d_fin_smooth (d01bd) is used to compute the value of the integral otherwise nag_quad_1d_fin_bad (d01aj) is used.
Pan's procedure can only be used if the λi * ${\lambda }_{i}^{*}$ are sufficiently distinct; nag_stat_prob_chisq_lincomb (g01jd) requires the λi * ${\lambda }_{i}^{*}$ to be at least 1%$1%$ distinct; see Section [Further Comments]. If the λi * ${\lambda }_{i}^{*}$ are at least 1%$1%$ distinct and n60$n\le 60$, then Pan's procedure is recommended; otherwise Imhof's procedure is recommended.

## References

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

## Parameters

### Compulsory Input Parameters

1:     rlam(n) – double array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
The weights, λi${\lambda }_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$, of the central χ2${\chi }^{2}$ variables.
Constraint: rlam(i)d${\mathbf{rlam}}\left(\mathit{i}\right)\ne {\mathbf{d}}$ for at least one i$\mathit{i}$. If method = 'P'${\mathbf{method}}=\text{'P'}$, then the λi * ${\lambda }_{\mathit{i}}^{*}$ must be at least 1%$1%$ distinct; see Section [Further Comments], for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
2:     d – double scalar
d$d$, the multiplier of the central χ2${\chi }^{2}$ variables.
Constraint: d0.0${\mathbf{d}}\ge 0.0$.
3:     c – double scalar
c$c$, the value of the constant.

### Optional Input Parameters

1:     method – string (length ≥ 1)
Indicates whether Pan's, Imhof's or an appropriately selected procedure is to be used.
method = 'P'${\mathbf{method}}=\text{'P'}$
Pan's method is used.
method = 'I'${\mathbf{method}}=\text{'I'}$
Imhof's method is used.
method = 'D'${\mathbf{method}}=\text{'D'}$
Pan's method is used if λi * ${\lambda }_{\mathit{i}}^{*}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$ are at least 1%$1%$ distinct and n60$n\le 60$; otherwise Imhof's method is used.
Default: 'D'$\text{'D'}$
Constraint: method = 'P'${\mathbf{method}}=\text{'P'}$, 'I'$\text{'I'}$ or 'D'$\text{'D'}$.
2:     n – int64int32nag_int scalar
Default: The dimension of the array rlam.
n$n$, the number of independent standard Normal variates, (central χ2${\chi }^{2}$ variates).
Constraint: n1${\mathbf{n}}\ge 1$.

work

### Output Parameters

1:     prob – double scalar
The lower tail probability for the linear combination of central χ2${\chi }^{2}$ variables.
2:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, n < 1${\mathbf{n}}<1$, or d < 0.0${\mathbf{d}}<0.0$, or method ≠ 'P'${\mathbf{method}}\ne \text{'P'}$, 'I'$\text{'I'}$ or 'D'$\text{'D'}$.
ifail = 2${\mathbf{ifail}}=2$
On entry, rlam(i) = d${\mathbf{rlam}}\left(\mathit{i}\right)={\mathbf{d}}$ for all values of i$\mathit{i}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
ifail = 3${\mathbf{ifail}}=3$
On entry, method = 'P'${\mathbf{method}}=\text{'P'}$ yet two successive values of the ordered λi * ${\lambda }_{\mathit{i}}^{*}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$, were not at least 1%$1%$ distinct.

## Accuracy

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

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

## Example

```function nag_stat_prob_chisq_lincomb_example
method = 'P';
rlam = [-9;
-7;
-5;
-3;
-1;
2;
4;
6;
8;
10];
d = 1;
c = 0;
[prob, ifail] = nag_stat_prob_chisq_lincomb(rlam, d, c, 'method', method)
```
```

prob =

0.5749

ifail =

0

```
```function g01jd_example
method = 'P';
rlam = [-9;
-7;
-5;
-3;
-1;
2;
4;
6;
8;
10];
d = 1;
c = 0;
[prob, ifail] = g01jd(rlam, d, c, 'method', method)
```
```

prob =

0.5749

ifail =

0

```