ORDST

Determines order statistics.

Required Arguments

X — Vector of length NOBS containing the data. (Input)

NOS — Number of order statistics. (Input)
NOS must be greater than or equal to one and less than or equal to NOBS.

OS — Vector of length NOS containing the order statistics. (Output)

NMISS — Number of missing values. (Output)

Optional Arguments

NOBS — Number of observations. (Input)
NOBS must be greater than or equal to one.
Default: NOBS = size (X,1).

IOPT — Option to choose the order statistics to be calculated. (Input)
Default: IOPT = 1.

IOPT

Action

0

Calculate the NOS order statistics listed in IOS.

1

Calculate the first NOS order statistics.

2

Calculate the last NOS order statistics.

IOS — If IOPT = 0, IOS is a vector of length NOS containing the ranks of the order statistics. (Input)
The elements of IOS must be greater than or equal to one and less than or equal to NOBS. If IOPT = 1 or 2, IOS is unreferenced and can be defined as a vector of length 1.

FORTRAN 90 Interface

Generic: CALL ORDST (X, NOS, OS, NMISS [])

Specific: The specific interface names are S_ORDST and D_ORDST.

FORTRAN 77 Interface

Single: CALL ORDST (NOBS, X, NOS, IOPT, IOS, OS, NMISS)

Double: The double precision name is DORDST.

Description

The routine ORDST determines order statistics from the data in X and returns them in the vector OS. The routine ORDST first checks to see if X is sorted, in which case the order statistics are merely picked from X. If X is not sorted, ORDST does either a complete or partial sort, depending on how many order statistics are requested. Since either the largest few order statistics or the smallest few are often of interest, the option parameter IOPT allows the user to obtain the largest or the smallest order statistics easily; otherwise (when IOPT is set to 0), the user specifies in the vector IOS exactly which order statistics are to be returned. If IOS is used, the order statistics returned in OS are in the same order as the indicators in IOS.

Comments

1. Workspace may be explicitly provided, if desired, by use of O2DST/DO2DST. The reference is:

CALL O2DST (NOBS, X, NOS, IOPT, IOS, OS, NMISS, WK)

The additional argument is as follows:

WK — Work vector of length NOBS.

2. Informational errors

Type

Code

Description

3

1

All of the observations are missing values. The elements of OS have been set to NaN (not a number).

3

2

NOS order statistics have been requested, but there are only
NOBS  NMISS valid observations. Order statistics greater than
NOBS  NMISS have been set to NaN (not a number).

3

3

Each value of IOS must be greater than 0 and less than or equal to the number of valid observations. The values of OS that are not defined have been set to NaN.

3. Missing values (NaN) are excluded from the analysis. Order statistics are based on the NOBS NMISS nonmissing elements of X.

Examples

Example 1

The data for these examples are from Hinkley (1977) and Velleman and Hoaglin (1981). They are the measurements (in inches) of precipitation in Minneapolis/St. Paul during the month of March for 30 consecutive years. In the first example, the first five order statistics from a sample of size 30 are obtained. Since IOPT is set to 1, IOS is not used.

 

USE ORDST_INT

USE UMACH_INT

USE WRRRN_INT

USE AMACH_INT

 

IMPLICIT NONE

INTEGER NOBS, NOS

PARAMETER (NOBS=30, NOS=5)

!

INTEGER NMISS, NOUT

REAL OS(NOS), 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)

CALL ORDST (X, NOS, OS, NMISS)

CALL WRRRN ('First five order statistics:', OS, 1, NOS, 1)

WRITE (NOUT,99999) NMISS

99999 FORMAT (' There are', I2, ' missing values.')

END

Output

 

First five order statistics:

1 2 3 4 5

0.3200 0.4700 0.5200 0.5900 0.7700

There are 0 missing values.

Example 2

In the second example, the last five order statistics from a sample of size 30 are obtained. This example uses the same data as in the first example, but this time the first two observations have been set to a missing value indicator (AMACH(6)). Note that since there are two missing values in the data set, the indices of the last five order statistics are numbers 24, 25, 26, 27, and 28. In this example, NMISS will be returned with a value of 2. The index of the last order statistic can be determined by NOBS  NMISS.

 

USE ORDST_INT

USE UMACH_INT

USE WRRRN_INT

USE AMACH_INT

 

IMPLICIT NONE

INTEGER IOPT, NOBS, NOS

PARAMETER (IOPT=2, NOBS=30, NOS=5)

!

INTEGER NMISS, NOUT

REAL OS(NOS), 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)

X(1) = AMACH(6)

X(2) = AMACH(6)

CALL ORDST (X, NOS, OS, NMISS, IOPT=IOPT)

CALL WRRRN ('Last five order statistics:', OS, 1, NOS, 1)

WRITE (NOUT,99999) NMISS

99999 FORMAT (' There are', I2, ' missing values.')

END

Output

 

Last five order statistics:

1 2 3 4 5

2.810 3.000 3.090 3.370 4.750

There are 2 missing values.

Example 3

In this example, we illustrate the use of IOS to specify exactly which order statistics are to be computed. We request what would be the last five order statistics from a sample of size 30, that is, order statistics 26, 27, 28, 29, and 30. As in example two, the data set has two missing values. Order statistics 29 and 30 are not defined, but since they are specifically requested, a warning message is issued and OS contains two missing values on return.

 

USE ORDST_INT

USE UMACH_INT

USE WRRRN_INT

USE AMACH_INT

 

IMPLICIT NONE

INTEGER IOPT, NOBS, NOS

PARAMETER (IOPT=0, NOBS=30, NOS=5)

!

INTEGER IOS(NOS), NMISS, NOUT

REAL OS(NOS), 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/

DATA IOS/26, 27, 28, 29, 30/

!

CALL UMACH (2, NOUT)

X(1) = AMACH(6)

X(2) = AMACH(6)

CALL ORDST (X, NOS, OS, NMISS, IOS=IOS, IOPT=IOPT)

CALL WRRRN ('Last five order statistics:', OS, 1, NOS, 1)

WRITE (NOUT,99999) NMISS

99999 FORMAT (' There are', I2, ' missing values.')

END

Output

 

*** WARNING ERROR 3 from ORDST. Each value of IOS must be greater than 0

*** and less than or equal to the number of valid observations,

*** NOBS-NMISS, which is 28. IOS contains 2 values outside of

*** this range. The corresponding values of OS have been set to

*** NaN (not a number).

 

Last five order statistics:

1 2 3 4 5

3.090 3.370 4.750 NaN NaN

There are 2 missing values.