# NAG C Library Function Document

## 1Purpose

nag_ranks_and_scores (g01dhc) computes the ranks, Normal scores, an approximation to the Normal scores or the exponential scores as requested by you.

## 2Specification

 #include #include
 void nag_ranks_and_scores (Nag_Scores scores, Nag_Ties ties, Integer n, const double x[], double r[], NagError *fail)

## 3Description

nag_ranks_and_scores (g01dhc) computes one of the following scores for a sample of observations, ${x}_{1},{x}_{2},\dots ,{x}_{n}$.
1. Rank Scores
The ranks are assigned to the data in ascending order, that is the $i$th observation has score ${s}_{i}=k$ if it is the $k$th smallest observation in the sample.
2. Normal Scores
The Normal scores are the expected values of the Normal order statistics from a sample of size $n$. If ${x}_{i}$ is the $k$th smallest observation in the sample, then the score for that observation, ${s}_{i}$, is $E\left({Z}_{k}\right)$ where ${Z}_{k}$ is the $k$th order statistic in a sample of size $n$ from a standard Normal distribution and $E$ is the expectation operator.
3. Blom, Tukey and van der Waerden Scores
These scores are approximations to the Normal scores. The scores are obtained by evaluating the inverse cumulative Normal distribution function, ${\Phi }^{-1}\left(·\right)$, at the values of the ranks scaled into the interval $\left(0,1\right)$ using different scaling transformations.
The Blom scores use the scaling transformation $\frac{{r}_{i}-\frac{3}{8}}{n+\frac{1}{4}}$ for the rank ${r}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$. Thus the Blom score corresponding to the observation ${x}_{i}$ is
 $si = Φ-1 ri - 38 n+14 .$
The Tukey scores use the scaling transformation $\frac{{r}_{i}-\frac{1}{3}}{n+\frac{1}{3}}$; the Tukey score corresponding to the observation ${x}_{i}$ is
 $si = Φ-1 ri - 13 n+13 .$
The van der Waerden scores use the scaling transformation $\frac{{r}_{i}}{n+1}$; the van der Waerden score corresponding to the observation ${x}_{i}$ is
 $si = Φ-1 ri n+1 .$
The van der Waerden scores may be used to carry out the van der Waerden test for testing for differences between several population distributions, see Conover (1980).
4. Savage Scores
The Savage scores are the expected values of the exponential order statistics from a sample of size $n$. They may be used in a test discussed by Savage (1956) and Lehmann (1975). If ${x}_{i}$ is the $k$th smallest observation in the sample, then the score for that observation is
 $si = EYk = 1n + 1n-1 + ⋯ + 1n-k+1 ,$
where ${Y}_{k}$ is the $k$th order statistic in a sample of size $n$ from a standard exponential distribution and $E$ is the expectation operator.
Ties may be handled in one of five ways. Let ${x}_{t\left(\mathit{i}\right)}$, for $\mathit{i}=1,2,\dots ,m$, denote $m$ tied observations, that is ${x}_{t\left(1\right)}={x}_{t\left(2\right)}=\cdots ={x}_{t\left(m\right)}$ with $t\left(1\right). If the rank of ${x}_{t\left(1\right)}$ is $k$, then if ties are ignored the rank of ${x}_{t\left(j\right)}$ will be $k+j-1$. Let the scores ignoring ties be ${s}_{t\left(1\right)}^{*},{s}_{t\left(2\right)}^{*},\dots ,{s}_{t\left(m\right)}^{*}$. Then the scores, ${s}_{t\left(\mathit{i}\right)}$, for $\mathit{i}=1,2,\dots ,m$, may be calculated as follows:
• – if averages are used, then ${s}_{t\left(i\right)}=\sum _{j=1}^{m}{s}_{t\left(j\right)}^{*}/m$;
• – if the lowest score is used, then ${s}_{t\left(i\right)}={s}_{t\left(1\right)}^{*}$;
• – if the highest score is used, then ${s}_{t\left(i\right)}={s}_{t\left(m\right)}^{*}$;
• – if ties are to be broken randomly, then ${s}_{t\left(i\right)}={s}_{t\left(I\right)}^{*}$ where $I\in \left\{\text{random permutation of ​}1,2,\dots ,m\right\}$;
• – if ties are to be ignored, then ${s}_{t\left(i\right)}={s}_{t\left(i\right)}^{*}$.
Blom G (1958) Statistical Estimates and Transformed Beta-variables Wiley
Conover W J (1980) Practical Nonparametric Statistics Wiley
Lehmann E L (1975) Nonparametrics: Statistical Methods Based on Ranks Holden–Day
Savage I R (1956) Contributions to the theory of rank order statistics – the two-sample case Ann. Math. Statist. 27 590–615
Tukey J W (1962) The future of data analysis Ann. Math. Statist. 33 1–67

## 5Arguments

1:    $\mathbf{scores}$Nag_ScoresInput
On entry: indicates which of the following scores are required.
${\mathbf{scores}}=\mathrm{Nag_RankScores}$
The ranks.
${\mathbf{scores}}=\mathrm{Nag_NormalScores}$
The Normal scores, that is the expected value of the Normal order statistics.
${\mathbf{scores}}=\mathrm{Nag_BlomScores}$
The Blom version of the Normal scores.
${\mathbf{scores}}=\mathrm{Nag_TukeyScores}$
The Tukey version of the Normal scores.
${\mathbf{scores}}=\mathrm{Nag_WaerdenScores}$
The van der Waerden version of the Normal scores.
${\mathbf{scores}}=\mathrm{Nag_SavageScores}$
The Savage scores, that is the expected value of the exponential order statistics.
Constraint: ${\mathbf{scores}}=\mathrm{Nag_RankScores}$, $\mathrm{Nag_NormalScores}$, $\mathrm{Nag_BlomScores}$, $\mathrm{Nag_TukeyScores}$, $\mathrm{Nag_WaerdenScores}$ or $\mathrm{Nag_SavageScores}$.
2:    $\mathbf{ties}$Nag_TiesInput
On entry: indicates which of the following methods is to be used to assign scores to tied observations.
${\mathbf{ties}}=\mathrm{Nag_AverageTies}$
The average of the scores for tied observations is used.
${\mathbf{ties}}=\mathrm{Nag_LowestTies}$
The lowest score in the group of ties is used.
${\mathbf{ties}}=\mathrm{Nag_HighestTies}$
The highest score in the group of ties is used.
${\mathbf{ties}}=\mathrm{Nag_RandomTies}$
The repeatable random number generator is used to randomly untie any group of tied observations.
${\mathbf{ties}}=\mathrm{Nag_IgnoreTies}$
Any ties are ignored, that is the scores are assigned to tied observations in the order that they appear in the data.
Constraint: ${\mathbf{ties}}=\mathrm{Nag_AverageTies}$, $\mathrm{Nag_LowestTies}$, $\mathrm{Nag_HighestTies}$, $\mathrm{Nag_RandomTies}$ or $\mathrm{Nag_IgnoreTies}$.
3:    $\mathbf{n}$IntegerInput
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}\ge 1$.
4:    $\mathbf{x}\left[{\mathbf{n}}\right]$const doubleInput
On entry: the sample of observations, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
5:    $\mathbf{r}\left[{\mathbf{n}}\right]$doubleOutput
On exit: contains the scores, ${s}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, as specified by scores.
6:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT_ARG_LT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

For ${\mathbf{scores}}=\mathrm{Nag_RankScores}$, the results should be accurate to machine precision.
For ${\mathbf{scores}}=\mathrm{Nag_SavageScores}$, the results should be accurate to a small multiple of machine precision.
For ${\mathbf{scores}}=\mathrm{Nag_NormalScores}$, the results should have a relative accuracy of at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(100×\epsilon ,{10}^{-8}\right)$ where $\epsilon$ is the machine precision.
For ${\mathbf{scores}}=\mathrm{Nag_BlomScores}$, $\mathrm{Nag_TukeyScores}$ or $\mathrm{Nag_WaerdenScores}$, the results should have a relative accuracy of at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(10×\epsilon ,{10}^{-12}\right)$.

## 8Parallelism and Performance

nag_ranks_and_scores (g01dhc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

If more accurate Normal scores are required nag_normal_scores_exact (g01dac) should be used with appropriate settings for the input argument etol.

## 10Example

This example computes and prints the Savage scores for a sample of five observations. The average of the scores of any tied observations is used.

### 10.1Program Text

Program Text (g01dhce.c)

### 10.2Program Data

Program Data (g01dhce.d)

### 10.3Program Results

Program Results (g01dhce.r)