Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_stat_ranks_and_scores (g01dh)

## Purpose

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

## Syntax

[r, ifail] = g01dh(scores, ties, x, 'n', n)
[r, ifail] = nag_stat_ranks_and_scores(scores, ties, x, 'n', n)

## Description

nag_stat_ranks_and_scores (g01dh) computes one of the following scores for a sample of observations, x1,x2,,xn${x}_{1},{x}_{2},\dots ,{x}_{n}$.
1. Rank Scores
The ranks are assigned to the data in ascending order, that is the i$i$th observation has score si = k${s}_{i}=k$ if it is the k$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$n$. If xi${x}_{i}$ is the k$k$th smallest observation in the sample, then the score for that observation, si${s}_{i}$, is E(Zk)$E\left({Z}_{k}\right)$ where Zk${Z}_{k}$ is the k$k$th order statistic in a sample of size n$n$ from a standard Normal distribution and E$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, Φ1( · )${\Phi }^{-1}\left(·\right)$, at the values of the ranks scaled into the interval (0,1)$\left(0,1\right)$ using different scaling transformations.
The Blom scores use the scaling transformation (ri(3/8))/(n + (1/4)) $\frac{{r}_{i}-\frac{3}{8}}{n+\frac{1}{4}}$ for the rank ri${r}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$. Thus the Blom score corresponding to the observation xi${x}_{i}$ is
 si = Φ − 1 (( ri − (3/8) )/(n + (1/4))) . $si = Φ-1 ( ri - 38 n+14 ) .$
The Tukey scores use the scaling transformation (ri(1/3))/(n + (1/3)) $\frac{{r}_{i}-\frac{1}{3}}{n+\frac{1}{3}}$; the Tukey score corresponding to the observation xi${x}_{i}$ is
 si = Φ − 1 (( ri − (1/3) )/(n + (1/3))) . $si = Φ-1 ( ri - 13 n+13 ) .$
The van der Waerden scores use the scaling transformation (ri)/(n + 1)$\frac{{r}_{i}}{n+1}$; the van der Waerden score corresponding to the observation xi${x}_{i}$ is
 si = Φ − 1 ((ri)/(n + 1)) . $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$n$. They may be used in a test discussed by Savage (1956) and Lehmann (1975). If xi${x}_{i}$ is the k$k$th smallest observation in the sample, then the score for that observation is
 si = E(Yk) = 1/n + 1/(n − 1) + ⋯ + 1/(n − k + 1) , $si = E(Yk) = 1n + 1n-1 + ⋯ + 1n-k+1 ,$
where Yk${Y}_{k}$ is the k$k$th order statistic in a sample of size n$n$ from a standard exponential distribution and E$E$ is the expectation operator.
Ties may be handled in one of five ways. Let xt(i)${x}_{t\left(\mathit{i}\right)}$, for i = 1,2,,m$\mathit{i}=1,2,\dots ,m$, denote m$m$ tied observations, that is xt(1) = xt(2) = = xt(m)${x}_{t\left(1\right)}={x}_{t\left(2\right)}=\cdots ={x}_{t\left(m\right)}$ with t(1) < t(2) < < t(m)$t\left(1\right). If the rank of xt(1)${x}_{t\left(1\right)}$ is k$k$, then if ties are ignored the rank of xt(j)${x}_{t\left(j\right)}$ will be k + j1$k+j-1$. Let the scores ignoring ties be st(1) * ,st(2) * ,,st(m) * ${s}_{t\left(1\right)}^{*},{s}_{t\left(2\right)}^{*},\dots ,{s}_{t\left(m\right)}^{*}$. Then the scores, st(i)${s}_{t\left(\mathit{i}\right)}$, for i = 1,2,,m$\mathit{i}=1,2,\dots ,m$, may be calculated as follows:
• – if averages are used, then st(i) = j = 1mst(j) * / m${s}_{t\left(i\right)}=\sum _{j=1}^{m}{s}_{t\left(j\right)}^{*}/m$;
• – if the lowest score is used, then st(i) = st(1) * ${s}_{t\left(i\right)}={s}_{t\left(1\right)}^{*}$;
• – if the highest score is used, then st(i) = st(m) * ${s}_{t\left(i\right)}={s}_{t\left(m\right)}^{*}$;
• – if ties are to be broken randomly, then st(i) = st(I) * ${s}_{t\left(i\right)}={s}_{t\left(I\right)}^{*}$ where I{random permutation of ​1,2,,m}$I\in \left\{\text{random permutation of ​}1,2,\dots ,m\right\}$;
• – if ties are to be ignored, then st(i) = st(i) * ${s}_{t\left(i\right)}={s}_{t\left(i\right)}^{*}$.

## References

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

## Parameters

### Compulsory Input Parameters

1:     scores – string (length ≥ 1)
Indicates which of the following scores are required.
scores = 'R'${\mathbf{scores}}=\text{'R'}$
The ranks.
scores = 'N'${\mathbf{scores}}=\text{'N'}$
The Normal scores, that is the expected value of the Normal order statistics.
scores = 'B'${\mathbf{scores}}=\text{'B'}$
The Blom version of the Normal scores.
scores = 'T'${\mathbf{scores}}=\text{'T'}$
The Tukey version of the Normal scores.
scores = 'V'${\mathbf{scores}}=\text{'V'}$
The van der Waerden version of the Normal scores.
scores = 'S'${\mathbf{scores}}=\text{'S'}$
The Savage scores, that is the expected value of the exponential order statistics.
Constraint: scores = 'R'${\mathbf{scores}}=\text{'R'}$, 'N'$\text{'N'}$, 'B'$\text{'B'}$, 'T'$\text{'T'}$, 'V'$\text{'V'}$ or 'S'$\text{'S'}$.
2:     ties – string (length ≥ 1)
Indicates which of the following methods is to be used to assign scores to tied observations.
ties = 'A'${\mathbf{ties}}=\text{'A'}$
The average of the scores for tied observations is used.
ties = 'L'${\mathbf{ties}}=\text{'L'}$
The lowest score in the group of ties is used.
ties = 'H'${\mathbf{ties}}=\text{'H'}$
The highest score in the group of ties is used.
ties = 'N'${\mathbf{ties}}=\text{'N'}$
The nonrepeatable random number generator is used to randomly untie any group of tied observations.
ties = 'R'${\mathbf{ties}}=\text{'R'}$
The repeatable random number generator is used to randomly untie any group of tied observations.
ties = 'I'${\mathbf{ties}}=\text{'I'}$
Any ties are ignored, that is the scores are assigned to tied observations in the order that they appear in the data.
Constraint: ties = 'A'${\mathbf{ties}}=\text{'A'}$, 'L'$\text{'L'}$, 'H'$\text{'H'}$, 'N'$\text{'N'}$, 'R'$\text{'R'}$ or 'I'$\text{'I'}$.
3:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
The sample of observations, xi${x}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array x.
n$n$, the number of observations.
Constraint: n1${\mathbf{n}}\ge 1$.

iwrk

### Output Parameters

1:     r(n) – double array
Contains the scores, si${s}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$, as specified by scores.
2:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, scores ≠ 'R'${\mathbf{scores}}\ne \text{'R'}$, 'N'$\text{'N'}$, 'B'$\text{'B'}$, 'T'$\text{'T'}$, 'V'$\text{'V'}$ or 'S'$\text{'S'}$, or ties ≠ 'A'${\mathbf{ties}}\ne \text{'A'}$, 'L'$\text{'L'}$, 'H'$\text{'H'}$, 'N'$\text{'N'}$, 'R'$\text{'R'}$ or 'I'$\text{'I'}$, or n < 1${\mathbf{n}}<1$.

## Accuracy

For scores = 'R'${\mathbf{scores}}=\text{'R'}$, the results should be accurate to machine precision.
For scores = 'S'${\mathbf{scores}}=\text{'S'}$, the results should be accurate to a small multiple of machine precision.
For scores = 'N'${\mathbf{scores}}=\text{'N'}$, the results should have a relative accuracy of at least max (100 × ε,108)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(100×\epsilon ,{10}^{-8}\right)$ where ε$\epsilon$ is the machine precision.
For scores = 'B'${\mathbf{scores}}=\text{'B'}$, 'T'$\text{'T'}$ or 'V'$\text{'V'}$, the results should have a relative accuracy of at least max (10 × ε,1012)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(10×\epsilon ,{10}^{-12}\right)$.

If more accurate Normal scores are required nag_stat_normal_scores_exact (g01da) should be used with appropriate settings for the input parameter etol.

## Example

```function nag_stat_ranks_and_scores_example
scores = 'Savage';
ties = 'Average';
x = [2;
0;
2;
2;
0];
[r, ifail] = nag_stat_ranks_and_scores(scores, ties, x)
```
```

r =

1.4500
0.3250
1.4500
1.4500
0.3250

ifail =

0

```
```function g01dh_example
scores = 'Savage';
ties = 'Average';
x = [2;
0;
2;
2;
0];
[r, ifail] = g01dh(scores, ties, x)
```
```

r =

1.4500
0.3250
1.4500
1.4500
0.3250

ifail =

0

```