# NAG FL Interfaceg01daf (normal_​scores_​exact)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

g01daf computes a 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 g01daf ( n, pp, etol, work, iw,
 Integer, Intent (In) :: n, iw Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: etol Real (Kind=nag_wp), Intent (Out) :: pp(n), errest, work(iw)
#include <nag.h>
 void g01daf_ (const Integer *n, double pp[], const double *etol, double *errest, double work[], const Integer *iw, Integer *ifail)
The routine may be called by the names g01daf or nagf_stat_normal_scores_exact.

## 3Description

If a sample of $n$ observations from any distribution (which may be denoted by ${x}_{1},{x}_{2},\dots ,{x}_{n}$), is sorted into ascending order, the $r$th smallest value in the sample is often referred to as the $r$th ‘order statistic’, sometimes denoted by ${x}_{\left(r\right)}$ (see Kendall and Stuart (1969)).
The order statistics, therefore, have the property
 $x(1)≤x(2)≤⋯≤x(n).$
(If $n=2r+1$, ${x}_{r+1}$ is the sample median.)
For samples originating from a known distribution, the distribution of each order statistic in a sample of given size may be determined. In particular, the expected values of the order statistics may be found by integration. If the sample arises from a Normal distribution, the expected values of the order statistics are referred to as the ‘Normal scores’. The Normal scores provide a set of reference values against which the order statistics of an actual data sample of the same size may be compared, to provide an indication of Normality for the sample. Normal scores have other applications; for instance, they are sometimes used as alternatives to ranks in nonparametric testing procedures.
g01daf computes the $r$th Normal score for a given sample size $n$ as
 $E(x(r))=∫-∞∞xrdGr,$
where
 $dGr=Arr- 1 (1-Ar)n-r d Ar β (r,n-r+ 1) , Ar=12π ∫-∞xre-t2/2 dt, r= 1,2,…,n,$
and $\beta$ denotes the complete beta function.
The routine attempts to evaluate the scores so that the estimated error in each score is less than the value etol specified by you. All integrations are performed in parallel and arranged so as to give good speed and reasonable accuracy.

## 4References

Kendall M G and Stuart A (1969) The Advanced Theory of Statistics (Volume 1) (3rd Edition) Griffin

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the size of the set.
Constraint: ${\mathbf{n}}>0$.
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{etol}$Real (Kind=nag_wp) Input
On entry: the maximum value for the estimated absolute error in the computed scores.
Constraint: ${\mathbf{etol}}>0.0$.
4: $\mathbf{errest}$Real (Kind=nag_wp) Output
On exit: a computed estimate of the maximum error in the computed scores (see Section 7).
5: $\mathbf{work}\left({\mathbf{iw}}\right)$Real (Kind=nag_wp) array Workspace
6: $\mathbf{iw}$Integer Input
On entry: the dimension of the array work as declared in the (sub)program from which g01daf is called.
Constraints:
• if , ${\mathbf{iw}}\ge 3×{\mathbf{n}}/2$;
• otherwise ${\mathbf{iw}}\ge 3×\left({\mathbf{n}}-1\right)/2$.
7: $\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}}=2$
On entry, ${\mathbf{etol}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{etol}}>0.0$.
${\mathbf{ifail}}=3$
The routine was unable to estimate the scores with estimated error less than etol. The best result obtained is returned together with the associated value of errest.
${\mathbf{ifail}}=4$
On entry, iw is too small. Minimum size required: $⟨\mathit{\text{value}}⟩$.
${\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

Errors are introduced by evaluation of the functions $d{G}_{r}$ and errors in the numerical integration process. Errors are also introduced by the approximation of the true infinite range of integration by a finite range $\left[a,b\right]$ but $a$ and $b$ are chosen so that this effect is of lower order than that of the other two factors. In order to estimate the maximum error the functions $d{G}_{r}$ are also integrated over the range $\left[a,b\right]$. g01daf returns the estimated maximum error as
 $errest=maxr [max(|a|,|b|)×|∫abdGr-1.0|] .$

## 8Parallelism and Performance

g01daf is not threaded in any implementation.

The time taken by g01daf depends on etol and n. For a given value of etol the timing varies approximately linearly with n.

## 10Example

The program below generates the Normal scores for samples of size $5$, $10$, $15$, and prints the scores and the computed error estimates.

### 10.1Program Text

Program Text (g01dafe.f90)

None.

### 10.3Program Results

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