A ranking is an ordering of a set of items, the first being either “ranked higher than”, “ranked lower than” or “ranked equal to” the second. If there can be ties in the ranking, the ranking is called a weak order. If there are no ties, it is called a total order. By reducing detailed measures to a sequence of ordinal numbers, rankings make it possible to evaluate complex information according to certain criteria. To put it simply, it is akin to sorting the runners in a race according to their time. In statistics, ranking is the conversion of data such that numerical or ordinal values are assigned to the data when they are sorted.

In the event of ties, there are many strategies for assigning rankings.

- Standard Competition Ranking (“1 2 2 4” ranking)
- Modified Competition Ranking (“1 3 3 4” ranking)
- Dense Ranking (“1 2 2 3” ranking)
- Ordinal Ranking (“1 2 3 4” ranking)
- Fractional Ranking (“1 2.5 2.5 4” ranking)

**Example**

For example, the timings of four 100m runners are 10.1, 9.8, 13.0 and 11.1. The ranks of these data items after sorting in ascending order is 2, 1, 4 and 3 respectively.

**Code**

In NM Dev, the class Rank is used to rank a set of data. It returns the sample ranks of the values. Ties and missing values can be handled in several ways. The MIN and MAX methods follow Standard Competition Ranking and Modified Competition Ranking respectively. The FIRST and LAST methods follow ordinal ranking, with items at higher indexes having higher and lower ranks respectively. The AVERAGE method follows fractional ranking while the method AS_26 breaks ties by following (Freeman, 1970). It adds 0.5 to the rank of each duplicated item.

` ````
```// create an array of doubles for our dataset
val values = doubleArrayOf(3.0, 1.0, 4.0, 1.0, 5.0, 9.0, 2.0, 6.0, 5.0, 3.0, 5.0)
// create Rank object
// MIN
var rank = Rank(values, Rank.TiesMethod.MIN)
println("MIN ranking: " +rank.ranks().joinToString())
// MAX
rank = Rank(values, Rank.TiesMethod.MAX)
println("MAX ranking: " +rank.ranks().joinToString())
// FIRST
rank = Rank(values, Rank.TiesMethod.FIRST)
println("FIRST ranking: " +rank.ranks().joinToString())
// LAST
rank = Rank(values, Rank.TiesMethod.LAST)
println("LAST ranking: " +rank.ranks().joinToString())
// AVERAGE
rank = Rank(values, Rank.TiesMethod.AVERAGE)
println("AVERAGE ranking: " +rank.ranks().joinToString())
// AS_26
rank = Rank(values, Rank.TiesMethod.AS_26)
println("AS_26 ranking: " +rank.ranks().joinToString())
// RANDOM
rank = Rank(values, Rank.TiesMethod.RANDOM)
println("RANDOM ranking: " +rank.ranks().joinToString())

` ````
```MIN ranking: 4.0, 1.0, 6.0, 1.0, 7.0, 11.0, 3.0, 10.0, 7.0, 4.0, 7.0
MAX ranking: 5.0, 2.0, 6.0, 2.0, 9.0, 11.0, 3.0, 10.0, 9.0, 5.0, 9.0
FIRST ranking: 4.0, 1.0, 6.0, 2.0, 7.0, 11.0, 3.0, 10.0, 8.0, 5.0, 9.0
LAST ranking: 5.0, 2.0, 6.0, 1.0, 9.0, 11.0, 3.0, 10.0, 8.0, 4.0, 7.0
AVERAGE ranking: 4.5, 1.5, 6.0, 1.5, 8.0, 11.0, 3.0, 10.0, 8.0, 4.5, 8.0
AS_26 ranking: 4.5, 1.5, 6.0, 1.5, 8.0, 11.0, 3.0, 10.0, 8.0, 4.5, 8.0
RANDOM ranking: 5.0, 1.0, 6.0, 2.0, 9.0, 11.0, 3.0, 10.0, 7.0, 4.0, 8.0