Rankings and Rank Correlations

This package implements various strategies for computing ranks and rank correlations.

StatsBase.ordinalrankFunction
ordinalrank(x; lt = isless, rev::Bool = false)

Return the ordinal ranking ("1234" ranking) of an array. The lt keyword allows providing a custom "less than" function; use rev=true to reverse the sorting order. All items in x are given distinct, successive ranks based on their position in sort(x; lt = lt, rev = rev). Missing values are assigned rank missing.

StatsBase.competerankFunction
competerank(x; lt = isless, rev::Bool = false)

Return the standard competition ranking ("1224" ranking) of an array. The lt keyword allows providing a custom "less than" function; use rev=true to reverse the sorting order. Items that compare equal are given the same rank, then a gap is left in the rankings the size of the number of tied items - 1. Missing values are assigned rank missing.

StatsBase.denserankFunction
denserank(x)

Return the dense ranking ("1223" ranking) of an array. The lt keyword allows providing a custom "less than" function; use rev=true to reverse the sorting order. Items that compare equal receive the same ranking, and the next subsequent rank is assigned with no gap. Missing values are assigned rank missing.

StatsBase.tiedrankFunction
tiedrank(x)

Return the tied ranking, also called fractional or "1 2.5 2.5 4" ranking, of an array. The lt keyword allows providing a custom "less than" function; use rev=true to reverse the sorting order. Items that compare equal receive the mean of the rankings they would have been assigned under ordinal ranking. Missing values are assigned rank missing.

StatsBase.corspearmanFunction
corspearman(x, y=x)

Compute Spearman's rank correlation coefficient. If x and y are vectors, the output is a float, otherwise it's a matrix corresponding to the pairwise correlations of the columns of x and y.

StatsBase.corkendallFunction
corkendall(x, y=x)

Compute Kendall's rank correlation coefficient, τ. x and y must both be either matrices or vectors.