irank {csranks} | R Documentation |
Compute ranks
Description
Compute ranks with flexible handling of ties.
Usage
irank(x, omega = 0, increasing = FALSE, na.rm = FALSE)
frank(x, omega = 0, increasing = FALSE, na.rm = FALSE)
Arguments
x |
vector of values to be ranked |
omega |
numeric value in [0,1], defining how ties in |
increasing |
logical; if |
na.rm |
logical; if |
Details
This function implements all possible definitions of ranks of the values in x
. Different definitions of the ranks are chosen through combinations of the two arguments
omega
and increasing
. Suppose x
is of length p
. If increasing=TRUE
, then the largest value in x
receives the rank p
and the smallest
the rank 1
. If increasing=FALSE
, then the largest value in x
receives the rank 1
and the smallest
the rank p
.
The value of omega
indicates how ties are handled. If there are no ties in x
, then the value of omega
does not affect the ranks and the only choice to be made is whether
the ranks should be increasing or decreasing with the values in x
. When there are ties in x
, however, then there are infinitely
many possible ranks that can be assigned to a tied value.
When increasing=TRUE
, then omega=0
leads to the smallest possible and omega=1
to the largest possible rank of a tied value. Values of omega
between
0 and 1 lead to values of the rank between the largest and smallest.
Value
Integer vector of the same length as x
containing the ranks.
Functions
-
frank()
: Compute fractional ranksThis function takes the ranking returned by
irank
and divides the result bylength(x)
. The result is a ranking with ranks in the interval [0,1]. An important special case occurs forincreasing=TRUE
andomega=1
: in this case, the rank of the valuex[j]
is equal to the empirical cdf ofx
evaluated atx[j]
.
Examples
# simple example without ties:
x <- c(3,8,-4,10,2)
irank(x, increasing=TRUE)
irank(x, increasing=FALSE)
# since there are no ties, the value of omega has no impact:
irank(x, increasing=TRUE, omega=0)
irank(x, increasing=TRUE, omega=0.5)
irank(x, increasing=TRUE, omega=1)
# simple example with ties:
x <- c(3,4,7,7,10,11,15,15,15,15)
irank(x, increasing=TRUE, omega=0) # smallest possible ranks
irank(x, increasing=TRUE, omega=0.5) # mid-ranks
irank(x, increasing=TRUE, omega=1) # largest possible ranks
# simple example of fractional ranks without ties:
x <- c(3,8,-4,10,2)
frank(x, increasing=TRUE)
frank(x, increasing=FALSE)