1
#' @title Count occurrences of pairs in rankings
2
#' @description  Counts the number of concordant, discordant and (left/right) ties between two rankings.
3
#'
4
#' @param x A numeric vector.
5
#' @param y A numeric vector with the same length as \code{x}.
6
#' @return A list containing
7
#' \item{concordant}{number of concordant pairs: \code{x[i]} > \code{x[j]} and \code{y[i]} > \code{y[j]}}
8
#' \item{discordant}{number of discordant pairs: \code{x[i]} > \code{x[j]} and \code{y[i]} < \code{y[j]}}
9
#' \item{ties}{number of tied pairs:  \code{x[i]} == \code{x[j]} and \code{y[i]} == \code{y[j]}}
10
#' \item{left}{number of left ties: \code{x[i]} == \code{x[j]} and \code{y[i]} != \code{y[j]}}
11
#' \item{right}{number of right ties: \code{x[i]} != \code{x[j]} and \code{y[i]} == \code{y[j]}}
12
#' @details Explicitly calculating the number of occurring cases is more robust 
13
#' than using correlation indices as given in the \code{cor} function. Especially 
14
#' left and right ties can significantly alter correlations. 
15
#' @author David Schoch
16
#' @examples
17
#' library(igraph)
18
#' tg <- threshold_graph(100,0.2)
19
#' compare_ranks(degree(tg),closeness(tg)) #only concordant pairs
20
#' compare_ranks(degree(tg),betweenness(tg)) #no discordant pairs
21
#' ## Rank Correlation
22
#' cor(degree(tg),closeness(tg),method='kendall') #1
23
#' cor(degree(tg),betweenness(tg),method='kendall') #not 1, although no discordant pairs
24
#' @export
25
compare_ranks <- function(x, y) {
26 2
    if (length(x) != length(y)) {
27 2
        stop("x and y must have the same length")
28
    }
29 2
    res <- checkPairs(x, y)
30 2
    return(res)
31
}
32

Read our documentation on viewing source code .

Loading