RANKS

Computes the ranks, normal scores, or exponential scores for a vector of observations.

Required Arguments

X — Vector of length NOBS containing the observations to be ranked. (Input)

SCORE — Vector of length NOBS containing the rank or a transformation of that rank of each observation. (Output)
X and SCORE may occupy the same memory.

Optional Arguments

NOBS — Number of observations. (Input)
Default: NOBS = size (X,1).

FUZZ — Value used to determine ties. (Input)
If X(I X(J) is less than or equal to FUZZ, then X(I) and X(J) are said to be tied.
Default: FUZZ = 0.0.

ITIE — Option for determining the method used to assign a score to tied observations. (Input)
Default: ITIE = 0.

ITIE

Method

0

The average of the scores of the tied observations is used.

1

The highest score in the group of ties is used.

2

The lowest score in the group of ties is used.

3

The tied observations are to be randomly untied using an IMSL random number generator.

ISCORE — Option for specifying the type of values returned in SCORE. (Input)
Default: ISCORE = 0.

ISCORE

Type

0

Ranks

1

Blom version of normal scores

2

Tukey version of normal scores

3

Van der Waerdan version of normal scores

4

Expected value of normal order statistics (For tied observations, the average of the expected normal scores are used.)

5

Savage scores (the expected value of exponential order statistics)

FORTRAN 90 Interface

Generic: CALL RANKS (X, SCORE [])

Specific: The specific interface names are S_RANKS and D_RANKS.

FORTRAN 77 Interface

Single: CALL RANKS (NOBS, X, FUZZ, ITIE, ISCORE, SCORE)

Double: The double precision name is DRANKS.

Description

The routine RANKS determines the ranks, or various transformations of the ranks of the data in X. Ties in the data can be resolved in four different ways, as specified in ITIE.

ISCORE = 0: Ranks

For this option, the values output in SCORE are the ordinary ranks of the data in X. If X(I) has the smallest value among those in X and there is no other element in X with this value, then
SCORE(I) = 1. If both X(I) and X(J) have the same smallest value, then

if ITIE = 0,   SCORE(I) = SCORE(J) = 1.5

if ITIE = 1,   SCORE(I) = SCORE(J) = 2.0

if ITIE = 2,   SCORE(I) = SCORE(J) = 1.0

if ITIE = 3,   SCORE(I) = 1.0 and SCORE(J) = 2.0
or               SCORE(I) = 2.0 and SCORE(J) = 1.0.

When the ties are resolved by use of routine RNUNF (see Chapter 18, “Random Number Generation”) to generate random numbers, different results may occur when running the same program at different times unless the “seed” of the random number generator is set explicitly by use of the routine RNSET (see Chapter 18, “Random Number Generation”). Ordinarily, there is no need to call the routine to set the seed, even if there are ties in the data.

ISCORE = 1: Normal Scores, Blom Version

Normal scores are expected values, or approximations to the expected values, of order statistics from a normal distribution. The simplest approximations are obtained by evaluating the inverse cumulative normal distribution function (routine ANORIN, see Chapter 18, “Random Number Generation”) at the ranks scaled into the open interval (0, 1). In the Blom version (see Blom 1958), the scaling transformation for the rank ri(1  ri  n, where n is the sample size, NOBS) is (ri  3/8)/(n + 1/4). The Blom normal score corresponding to the observation with rank ri is

 

where Φ( ) is the normal cumulative distribution function.

Adjustments for ties are made after the normal score transformation. That is, if X(I) equals X(J) (within FUZZ) and their value is the k-th smallest in the data set, the Blom normal scores are determined for ranks of k and k + 1, and then these normal scores are averaged or selected in the manner specified by ITIE. (Whether the transformations are made first or ties are resolved first makes no difference except when averaging is done.)

ISCORE = 2: Normal Scores, Tukey Version

In the Tukey version (see Tukey 1962), the scaling transformation for the rank ri is (ri  1/3)/(n + 1/3). The Tukey normal score corresponding to the observation with rank ri is

 

Ties are handled in the same way as discussed above for the Blom normal scores.

ISCORE = 3: Normal Scores, Van der Waerden Version

In the Van der Waerden version (see Lehmann 1975, page 97), the scaling transformation for the rank ri is ri / (n + 1). The Van der Waerden normal score corresponding to the observation with rank ri is

 

Ties are handled in the same way as discussed above for the Blom normal scores.

ISCORE = 4: Expected Value of Normal Order Statistics

For this option, the values output in SCORE are the expected values of the normal order statistics from a sample of size NOBS. If the value in X(I) is the k-th smallest, then the value output in SCORE(I) is E(Zk), where E( ) is the expectation operator and Zk is the k-th order statistic in a sample of size NOBS from a standard normal distribution. Such expected values are computed by the routine ENOS (see Chapter 20, “Mathematical Support”). Ties are handled in the same way as discussed above for the Blom normal scores.

ISCORE = 5: Savage Scores

For this option, the values output in SCORE are the expected values of the exponential order statistics from a sample of size NOBS. These values are called Savage scores because of their use in a test discussed by Savage (1956) (see Lehman 1975). If the value in X(I) is the k-th smallest, then the value output in SCORE(I) is E(Yk), where Yk is the k-th order statistic in a sample of size NOBS from a standard exponential distribution. The expected value of the k-th order statistic from an exponential sample of size n (NOBS) is

 

Ties are handled in the same way as discussed above for the Blom normal scores.

The example uses all of these options with the same data set, which contains some ties. The ties are handled different ways in this example.

Comments

1. Workspace may be explicitly provided, if desired, by use R2NKS/DR2NKS. The reference is:

CALL R2NKS (NOBS, X, FUZZ, ITIE, ISCORE, SCORE, IWK)

The additional argument is:

IWK — Integer work vector of length NOBS.

2. The routine RNSET (see Chapter 18, “Random Number Generation”) can be used to initialize the seed of the random number generator used to break ties. If the seed is not initialized by RNSET; different runs of the same program can yield different results if there are tied observations and ITIE = 3.

Example

The data for this example, from Hinkley (1977), are the same used in several examples in this chapter. There are 30 observations. Note that the fourth and sixth observations are tied and that the third and twentieth are tied.

 

USE RANKS_INT

USE UMACH_INT

USE RNSET_INT

 

IMPLICIT NONE

INTEGER NOBS

PARAMETER (NOBS=30)

!

INTEGER ISCORE, ISEED, ITIE, NOUT

REAL FUZZ, SCORE(NOBS), X(NOBS)

!

DATA X/0.77, 1.74, 0.81, 1.20, 1.95, 1.20, 0.47, 1.43, 3.37,&

2.20, 3.00, 3.09, 1.51, 2.10, 0.52, 1.62, 1.31, 0.32, 0.59, &

0.81, 2.81, 1.87, 1.18, 1.35, 4.75, 2.48, 0.96, 1.89, 0.90, &

2.05/

!

CALL UMACH (2, NOUT)

! Ranks.

ISCORE = 0

! Average ties.

ITIE = 0

FUZZ = 0.0

!

CALL RANKS (X, SCORE, ISCORE=ISCORE, ITIE=ITIE, FUZZ=FUZZ)

WRITE (NOUT,99994) SCORE

99994 FORMAT (' Ranks', /, (1X,10F7.1))

! Blom normal scores.

ISCORE = 1

! Take largest ranks for ties.

ITIE = 1

FUZZ = 0.0

!

CALL RANKS (X, SCORE, ISCORE=ISCORE, ITIE=ITIE, FUZZ=FUZZ)

WRITE (NOUT,99995) SCORE

99995 FORMAT (/, ' Blom normal scores', /, (1X,10F7.3))

! Tukey normal scores.

ISCORE = 2

! Take smallest ranks for ties.

ITIE = 2

FUZZ = 0.0

!

CALL RANKS (X, SCORE, ISCORE=ISCORE, ITIE=ITIE, FUZZ=FUZZ)

WRITE (NOUT,99996) SCORE

99996 FORMAT (/, ' Tukey normal scores', /, (1X,10F7.3))

! Van der Waerden scores.

ISCORE = 3

! Randomly resolve ties.

ISEED = 123457

CALL RNSET (ISEED)

ITIE = 3

FUZZ = 0.0

!

CALL RANKS (X, SCORE, ISCORE=ISCORE, ITIE=ITIE, FUZZ=FUZZ)

WRITE (NOUT,99997) SCORE

99997 FORMAT (/, ' Van der Waerden scores', /, (1X,10F7.3))

! Expected value of normal O. S.

ISCORE = 4

! Average ties.

ITIE = 0

FUZZ = 0.0

!

CALL RANKS (X, SCORE, ISCORE=ISCORE, ITIE=ITIE, FUZZ=FUZZ)

WRITE (NOUT,99998) SCORE

99998 FORMAT (/, ' Expected values of normal order statistics', /,&

(1X,10F7.3))

! Savage scores.

ISCORE = 5

! Average ties.

ITIE = 0

FUZZ = 0.0

!

CALL RANKS (X, SCORE, ISCORE=ISCORE, ITIE=ITIE, FUZZ=FUZZ)

WRITE (NOUT,99999) SCORE

99999 FORMAT (/, ' Expected values of exponential order statistics', &

/, (1X,10F7.2))

END

Output

 

Ranks

5.0 18.0 6.5 11.5 21.0 11.5 2.0 15.0 29.0 24.0

27.0 28.0 16.0 23.0 3.0 17.0 13.0 1.0 4.0 6.5

26.0 19.0 10.0 14.0 30.0 25.0 9.0 20.0 8.0 22.0

 

Blom normal scores

-1.024 0.209 -0.776 -0.294 0.473 -0.294 -1.610 -0.041 1.610 0.776

1.176 1.361 0.041 0.668 -1.361 0.125 -0.209 -2.040 -1.176 -0.776

1.024 0.294 -0.473 -0.125 2.040 0.893 -0.568 0.382 -0.668 0.568

 

Tukey normal scores

-1.020 0.208 -0.890 -0.381 0.471 -0.381 -1.599 -0.041 1.599 0.773

1.171 1.354 0.041 0.666 -1.354 0.124 -0.208 -2.015 -1.171 -0.890

1.020 0.293 -0.471 -0.124 2.015 0.890 -0.566 0.381 -0.666 0.566

 

Van der Waerden scores

-0.989 0.204 -0.753 -0.287 0.460 -0.372 -1.518 -0.040 1.518 0.753

1.131 1.300 0.040 0.649 -1.300 0.122 -0.204 -1.849 -1.131 -0.865

0.989 0.287 -0.460 -0.122 1.849 0.865 -0.552 0.372 -0.649 0.552

Expected values of normal order statistics

-1.026 0.209 -0.836 -0.338 0.473 -0.338 -1.616 -0.041 1.616 0.777

1.179 1.365 0.041 0.669 -1.365 0.125 -0.209 -2.043 -1.179 -0.836

1.026 0.294 -0.473 -0.125 2.043 0.894 -0.568 0.382 -0.669 0.568

 

Expected values of exponential order statistics

0 18 0.89 0.24 0.47 1.17 0.47 0.07 0.68 2.99 1.54

2.16 2.49 0.74 1.40 0.10 0.81 0.56 0.03 0.14 0.24

1.91 0.98 0.40 0.61 3.99 1.71 0.35 1.07 0.30 1.28