Learn R Programming

csranks (version 1.0.1)

irank: Compute ranks from feature values

Description

Given estimates of a certain feature for a set of populations, calculate the integer ranks of populations, i.e. places in ranking done by feature values. The larger (or smaller) feature value, the higher the place and the lower the integer rank (lowest, 1, is the best place).

Usage

irank(x, omega = 0, increasing = FALSE, na.rm = FALSE)

frank(x, omega = 0, increasing = FALSE, na.rm = FALSE)

Value

vector of the same length as x containing the ranks

Arguments

x

vector of values to be ranked

omega

numeric; numeric value in [0,1], each corresponding to a different definition of the rank; default is 0. See Details.

increasing

logical; if TRUE, then large elements in x receive a large rank. In other words, larger values in x are lower in ranking. Otherwise, large elements receive small ranks.

na.rm

logical; if TRUE, then NA's are removed from x. In other case the output for NAs is NA and for other values it's for extreme possibilities that NA values are actually in first or last positions of ranking.

Functions

  • frank(): Compute fractional ranks

    This method returns ranks in form of fractions from [0-1] interval. Smaller values (closer to 0) indicate higher rank.

Details

omega (\(\omega\)) value determines, how equal entries in x should be ranked; in other words how to handle ex aequo cases. If there are none, then the parameter does not affect the output of this function. For example, let's say, that \(n\) largest entries in x are equal. Those entries could receive (minimum) rank 1 or (maximum) rank \(n\) or some value in between.

Suppose, that we want to assign rank to \(n\) equal values in an array. Denote their minimum rank as \(r\) and maximum as \(R = r + n - 1\). Then the assigned rank is an average of minimum and maximum rank, weighted by \(\omega\): $$r(1-\omega) + R\omega$$

Examples

Run this code
irank(c(4,3,1,10,7))
irank(c(4,3,1,10,7), omega=1) # equal to previous ranks because there are no ties
irank(c(4,3,1,10,7), omega=0.5) # equal to previous ranks because there are no ties
irank(c(4,4,4,3,1,10,7,7))
irank(c(4,4,4,3,1,10,7,7), omega=1)
irank(c(4,4,4,3,1,10,7,7), omega=0.5) 
frank(c(4,3,1,10,7))
frank(c(4,3,1,10,7), omega=1) # equal to previous ranks because there are no ties
frank(c(4,3,1,10,7), omega=0.5) # mid-ranks, equal to previous ranks because there are no ties
frank(c(4,4,4,3,1,10,7,7))
frank(c(4,4,4,3,1,10,7,7), omega=1)
frank(c(4,4,4,3,1,10,7,7), omega=0.5) # mid-ranks

Run the code above in your browser using DataLab