1
#' @title Check preservation
2
#' @description Checks if a partial ranking is preserved in the ranking induced by `scores`.
3
#' @param P A partial ranking as matrix object calculated with [neighborhood_inclusion]
4
#'    or [positional_dominance].
5
#' @param scores Numeric vector containing the scores of a centrality index.
6
#' @details In order for a score vector to preserve a partial ranking, the following 
7
#' condition must be fulfilled:
8
#' \code{P[u,v]==1 & scores[i]<=scores[j]}.
9
#' @return Logical scaler whether \code{scores} preserves the relations in \code{P}.
10
#' @author David Schoch
11
#' @examples
12
#' 
13
#' library(igraph)
14
#' # standard measures of centrality preserve the neighborhood inclusion preorder
15
#' g <- graph.empty(n=11,directed = FALSE)
16
#' g <- add_edges(g,c(1,11,2,4,3,5,3,11,4,8,5,9,5,11,6,7,6,8,
17
#'                    6,10,6,11,7,9,7,10,7,11,8,9,8,10,9,10))
18
#' P<-neighborhood_inclusion(g)
19
#' 
20
#' is_preserved(P,degree(g))
21
#' is_preserved(P,betweenness(g))
22
#' is_preserved(P,closeness(g))
23
#' @export
24
is_preserved <- function(P, scores) {
25 1
    n <- nrow(P)
26 1
    preserved <- preserve(P, scores, n) == 0
27
    
28 1
    return(preserved)
29
}

Read our documentation on viewing source code .

Loading