irank | R Documentation |
Compute ranks with flexible handling of ties.
irank(x, omega = 0, increasing = FALSE, na.rm = FALSE)
frank(x, omega = 0, increasing = FALSE, na.rm = FALSE)
x |
vector of values to be ranked |
omega |
numeric value in [0,1], defining how ties in |
increasing |
logical; if |
na.rm |
logical; if |
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.
Integer vector of the same length as x
containing the ranks.
frank()
: Compute fractional ranks
This function takes the ranking returned by irank
and divides the result by length(x)
. The result is a ranking with
ranks in the interval [0,1]. An important special case occurs for increasing=TRUE
and omega=1
: in this case, the rank
of the value x[j]
is equal to the empirical cdf of x
evaluated at x[j]
.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.