# NAG FL Interfaceg01dcf (normal_​scores_​var)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine g01dcf ( n, exp1, exp2, vec,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: exp1, exp2, sumssq Real (Kind=nag_wp), Intent (Out) :: vec(n*(n+1)/2)
#include <nag.h>
 void g01dcf_ (const Integer *n, const double *exp1, const double *exp2, const double *sumssq, double vec[], Integer *ifail)
The routine may be called by the names g01dcf or nagf_stat_normal_scores_var.

## 3Description

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:
1. (a)for any $i=1,2,\dots ,n$, $\sum _{j=1}^{n}{V}_{ij}=1$
2. (b)${V}_{12}={V}_{11}+{m}_{n}^{2}-{m}_{n}{m}_{n-1}-1$
3. (c)the trace of $V$ is $tr\left(V\right)=n-\sum _{i=1}^{n}{m}_{i}^{2}$
4. (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.

## 4References

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

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the sample size.
Constraint: ${\mathbf{n}}>0$.
2: $\mathbf{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: $\mathbf{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: $\mathbf{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: $\mathbf{vec}\left({\mathbf{n}}×\left({\mathbf{n}}+1\right)/2\right)$Real (Kind=nag_wp) array Output
On exit: the upper triangle of the $n×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: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}>0$.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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

## 8Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
g01dcf is not threaded in any implementation.

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

## 10Example

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.1Program Text

Program Text (g01dcfe.f90)

None.

### 10.3Program Results

Program Results (g01dcfe.r)