G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG01DCF

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

G01DCF computes an approximation to the variance-covariance matrix of an ordered set of independent observations from a Normal distribution with mean $0.0$ and standard deviation $1.0$.

## 2  Specification

 SUBROUTINE G01DCF ( N, EXP1, EXP2, SUMSSQ, VEC, IFAIL)
 INTEGER N, IFAIL REAL (KIND=nag_wp) EXP1, EXP2, SUMSSQ, VEC(N*(N+1)/2)

## 3  Description

G01DCF is an adaptation of the Applied Statistics Algorithm AS 128, see Davis and Stephens (1978). An approximation to the variance-covariance matrix, $V$, using a Taylor series expansion of the Normal distribution function is discussed in David and Johnson (1954).
However, convergence is slow for extreme variances and covariances. The present routine uses the David–Johnson approximation to provide an initial approximation and improves upon it by use of the following identities for the matrix.
For a sample of size $n$, let ${m}_{i}$ be the expected value of the $i$th largest order statistic, then:
 (a) for any $i=1,2,\dots ,n$, $\sum _{j=1}^{n}{V}_{ij}=1$ (b) ${V}_{12}={V}_{11}+{m}_{n}^{2}-{m}_{n}{m}_{n-1}-1$ (c) the trace of $V$ is $tr\left(V\right)=n-\sum _{i=1}^{n}{m}_{i}^{2}$ (d) ${V}_{ij}={V}_{ji}={V}_{rs}={V}_{sr}$ where $r=n+1-i$, $s=n+1-j$ and $i,j=1,2,\dots ,n$. Note that only the upper triangle of the matrix is calculated and returned column-wise in vector form.
David F N and Johnson N L (1954) Statistical treatment of censored data, Part 1. Fundamental formulae Biometrika 41 228–240
Davis C S and Stephens M A (1978) Algorithm AS 128: approximating the covariance matrix of Normal order statistics Appl. Statist. 27 206–212

## 5  Parameters

1:     $\mathrm{N}$ – INTEGERInput
On entry: $n$, the sample size.
Constraint: ${\mathbf{N}}>0$.
2:     $\mathrm{EXP1}$ – REAL (KIND=nag_wp)Input
On entry: the expected value of the largest Normal order statistic, ${m}_{n}$, from a sample of size $n$.
3:     $\mathrm{EXP2}$ – REAL (KIND=nag_wp)Input
On entry: the expected value of the second largest Normal order statistic, ${m}_{n-1}$, from a sample of size $n$.
4:     $\mathrm{SUMSSQ}$ – REAL (KIND=nag_wp)Input
On entry: the sum of squares of the expected values of the Normal order statistics from a sample of size $n$.
5:     $\mathrm{VEC}\left({\mathbf{N}}×\left({\mathbf{N}}+1\right)/2\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: the upper triangle of the $n$ by $n$ variance-covariance matrix packed by column. Thus element ${V}_{ij}$ is stored in ${\mathbf{VEC}}\left(i+j×\left(j-1\right)/2\right)$, for $1\le i\le j\le n$.
6:     $\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, if you are not familiar with this parameter, 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).

## 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).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{N}}<1$.
${\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

For $n\le 20$, where comparison with the exact values can be made, the maximum error is less than $0.0001$.

## 8  Parallelism and Performance

Not applicable.

The time taken by G01DCF is approximately proportional to ${n}^{2}$.
The arguments ${\mathbf{EXP1}}$ ($={m}_{n}$), ${\mathbf{EXP2}}$ ($={m}_{n-1}$) and ${\mathbf{SUMSSQ}}$ ($=\sum _{j=1}^{n}{m}_{j}^{2}$) may be found from the expected values of the Normal order statistics obtained from G01DAF (exact) or G01DBF (approximate).

## 10  Example

A program to compute the variance-covariance matrix for a sample of size $6$. G01DAF is called to provide values for EXP1, EXP2 and SUMSSQ.

### 10.1  Program Text

Program Text (g01dcfe.f90)

None.

### 10.3  Program Results

Program Results (g01dcfe.r)