NAG Library Routine Document

g01dcf (normal_scores_var)


    1  Purpose
    7  Accuracy


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.


Fortran Interface
Subroutine g01dcf ( n, exp1, exp2, sumssq, vec, ifail)
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)
C Header Interface
#include nagmk26.h
void  g01dcf_ (const Integer *n, const double *exp1, const double *exp2, const double *sumssq, double vec[], Integer *ifail)


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 mi be the expected value of the ith largest order statistic, then:
(a) for any i=1,2,,n, j=1nVij=1
(b) V12=V11+mn2-mnmn-1-1
(c) the trace of V is trV=n-i=1nmi2
(d) Vij=Vji=Vrs=Vsr where r=n+1-i, s=n+1-j and i,j=1,2,,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


1:     n – IntegerInput
On entry: n, the sample size.
Constraint: n>0.
2:     exp1 – Real (Kind=nag_wp)Input
On entry: the expected value of the largest Normal order statistic, mn, from a sample of size n.
3:     exp2 – Real (Kind=nag_wp)Input
On entry: the expected value of the second largest Normal order statistic, mn-1, from a sample of size n.
4:     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:     vecn×n+1/2 – Real (Kind=nag_wp) arrayOutput
On exit: the upper triangle of the n by n variance-covariance matrix packed by column. Thus element Vij is stored in veci+j×j-1/2, for 1ijn.
6:     ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ 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​ 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 -1​ or ​1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

Error Indicators and Warnings

If on entry 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:
On entry, n=value.
Constraint: n>0.
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
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.
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.


For n20, where comparison with the exact values can be made, the maximum error is less than 0.0001.

Parallelism and Performance

g01dcf is not threaded in any implementation.

Further Comments

The time taken by g01dcf is approximately proportional to n2.
The arguments exp1 (=mn), exp2 (=mn-1) and sumssq (=j=1nmj2) may be found from the expected values of the Normal order statistics obtained from g01daf (exact) or g01dbf (approximate).


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.

Program Text

Program Text (g01dcfe.f90)

Program Data


Program Results

Program Results (g01dcfe.r)

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