# NAG FL Interfaceg01dbf (normal_​scores_​approx)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

g01dbf calculates an approximation to the set of Normal Scores, i.e., the expected values of an ordered set of independent observations from a Normal distribution with mean $0.0$ and standard deviation $1.0$.

## 2Specification

Fortran Interface
 Subroutine g01dbf ( n, pp,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (Out) :: pp(n)
#include <nag.h>
 void g01dbf_ (const Integer *n, double pp[], Integer *ifail)
The routine may be called by the names g01dbf or nagf_stat_normal_scores_approx.

## 3Description

g01dbf is an adaptation of the Applied Statistics Algorithm AS $177.3$, see Royston (1982). If you are particularly concerned with the accuracy with which g01dbf computes the expected values of the order statistics (see Section 7), then g01daf which is more accurate should be used instead at a cost of increased storage and computing time.
Let ${x}_{\left(1\right)},{x}_{\left(2\right)},\dots ,{x}_{\left(n\right)}$ be the order statistics from a random sample of size $n$ from the standard Normal distribution. Defining
 $Pr,n=Φ(-E(x(r)))$
and
 $Qr,n=r-ε n+γ , r= 1,2,…,n,$
where $E\left({x}_{\left(r\right)}\right)$ is the expected value of ${x}_{\left(r\right)}$, the current routine approximates the Normal upper tail area corresponding to $E\left({x}_{\left(r\right)}\right)$ as,
 $P~r,n=Qr,n+δ1nQr,nλ+δ2nQr,n 2λ-Cr,n.$
for $\mathit{r}=1,2,3$, and $r\ge 4$. Estimates of $\epsilon$, $\gamma$, ${\delta }_{1}$, ${\delta }_{2}$ and $\lambda$ are obtained. A small correction ${C}_{r,n}$ to ${\stackrel{~}{P}}_{r,n}$ is necessary when $r\le 7$ and $n\le 20$.
The approximation to $E\left({X}_{\left(r\right)}\right)$ is thus given by
 $E ( x (r) ) = - Φ-1 ( P ~ r , n ) , r =1,2,…,n .$
Values of the inverse Normal probability integral ${\Phi }^{-1}$ are obtained from g01faf.

## 4References

Royston J P (1982) Algorithm AS 177: expected normal order statistics (exact and approximate) Appl. Statist. 31 161–165

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the size of the sample.
Constraint: ${\mathbf{n}}\ge 1$.
2: $\mathbf{pp}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: the Normal scores. ${\mathbf{pp}}\left(\mathit{i}\right)$ contains the value $E\left({x}_{\left(\mathit{i}\right)}\right)$, for $\mathit{i}=1,2,\dots ,n$.
3: $\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}}\ge 1$.
${\mathbf{ifail}}=-99$
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 2000$, the maximum error is $0.0001$, but g01dbf is usually accurate to $5$ or $6$ decimal places. For $n$ up to $5000$, comparison with the exact scores calculated by g01daf shows that the maximum error is $0.001$.

## 8Parallelism and Performance

g01dbf is not threaded in any implementation.

The time taken by g01dbf is proportional to $n$.

## 10Example

A program to calculate the expected values of the order statistics for a sample of size $10$.

### 10.1Program Text

Program Text (g01dbfe.f90)

None.

### 10.3Program Results

Program Results (g01dbfe.r)
This shows a Q-Q plot for a randomly generated set of data. The normal scores have been calculated using g01dbf and the sample quantiles obtained by sorting the observed data using m01caf. A reference line at $y=x$ is also shown.