1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
|
## -----------------------------------------------------------------------
##
## IGraph R package
## Copyright (C) 2015 Gabor Csardi <csardi.gabor@gmail.com>
## 334 Harvard street, Cambridge, MA 02139 USA
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301 USA
##
## -----------------------------------------------------------------------
#' @include auto.R
NULL
#' Centralization of a graph
#'
#' Centralization is a method for creating a graph level centralization
#' measure from the centrality scores of the vertices.
#'
#' Centralization is a general method for calculating a graph-level
#' centrality score based on node-level centrality measure. The formula for
#' this is
#' \deqn{C(G)=\sum_v (\max_w c_w - c_v),}{ C(G)=sum( max(c(w), w) - c(v),v),}
#' where \eqn{c_v}{c(v)} is the centrality of vertex \eqn{v}.
#'
#' The graph-level centrality score can be normalized by dividing by the
#' maximum theoretical score for a graph with the same number of vertices,
#' using the same parameters, e.g. directedness, whether we consider loop
#' edges, etc.
#'
#' For degree, closeness and betweenness the most centralized structure is
#' some version of the star graph, in-star, out-star or undirected star.
#'
#' For eigenvector centrality the most centralized structure is the graph
#' with a single edge (and potentially many isolates).
#'
#' \code{centralize} implements general centralization formula to calculate
#' a graph-level score from vertex-level scores.
#'
#' @param scores The vertex level centrality scores.
#' @param theoretical.max Real scalar. The graph level centrality score of
#' the most centralized graph with the same number of vertices as the graph
#' under study. This is only used if the \code{normalized} argument is set
#' to \code{TRUE}.
#' @param normalized Logical scalar. Whether to normalize the graph level
#' centrality score by dividing by the supplied theoretical maximum.
#' @return A real scalar, the centralization of the graph from which
#' \code{scores} were derived.
#'
#' @aliases centralization centralize.scores
#' @family centralization related
#'
#' @export
#' @references Freeman, L.C. (1979). Centrality in Social Networks I:
#' Conceptual Clarification. \emph{Social Networks} 1, 215--239.
#'
#' Wasserman, S., and Faust, K. (1994). \emph{Social Network Analysis:
#' Methods and Applications.} Cambridge University Press.
#'
#' @examples
#' # A BA graph is quite centralized
#' g <- sample_pa(1000, m=4)
#' centr_degree(g)$centralization
#' centr_clo(g, mode="all")$centralization
#' centr_eigen(g, directed=FALSE)$centralization
#'
#' # The most centralized graph according to eigenvector centrality
#' g0 <- graph( c(2,1), n=10, dir=FALSE )
#' g1 <- make_star(10, mode="undirected")
#' centr_eigen(g0)$centralization
#' centr_eigen(g1)$centralization
centralize <- centralize
#' Centralize a graph according to the degrees of vertices
#'
#' See \code{\link{centralize}} for a summary of graph centralization.
#'
#' @param graph The input graph.
#' @param mode This is the same as the \code{mode} argument of
#' \code{degree}.
#' @param loops Logical scalar, whether to consider loops edges when
#' calculating the degree.
#' @param normalized Logical scalar. Whether to normalize the graph level
#' centrality score by dividing by the theoretical maximum.
#' @return A named list with the following components:
#' \item{res}{The node-level centrality scores.}
#' \item{centralization}{The graph level centrality index.}
#' \item{theoretical_max}{The maximum theoretical graph level
#' centralization score for a graph with the given number of vertices,
#' using the same parameters. If the \code{normalized} argument was
#' \code{TRUE}, then the result was divided by this number.}
#'
#' @aliases centralization.degree
#' @family centralization related
#'
#' @export
#'
#' @examples
#' # A BA graph is quite centralized
#' g <- sample_pa(1000, m = 4)
#' centr_degree(g)$centralization
#' centr_clo(g, mode = "all")$centralization
#' centr_betw(g, directed = FALSE)$centralization
#' centr_eigen(g, directed = FALSE)$centralization
centr_degree <- centr_degree
#' Theoretical maximum for degree centralization
#'
#' See \code{\link{centralize}} for a summary of graph centralization.
#'
#' @param graph The input graph. It can also be \code{NULL}, if
#' \code{nodes}, \code{mode} and \code{loops} are all given.
#' @param nodes The number of vertices. This is ignored if the graph is given.
#' @param mode This is the same as the \code{mode} argument of
#' \code{degree}.
#' @param loops Logical scalar, whether to consider loops edges when
#' calculating the degree.
#' @return Real scalar, the theoratical maximum (unnormalized) graph degree
#' centrality score for graphs with given order and other parameters.
#'
#' @aliases centralization.degree.tmax
#' @family centralization related
#'
#' @export
#'
#' @examples
#' # A BA graph is quite centralized
#' g <- sample_pa(1000, m = 4)
#' centr_degree(g, normalized = FALSE)$centralization %>%
#' `/`(centr_degree_tmax(g))
#' centr_degree(g, normalized = TRUE)$centralization
centr_degree_tmax <- centr_degree_tmax
#' Centralize a graph according to the betweenness of vertices
#'
#' See \code{\link{centralize}} for a summary of graph centralization.
#'
#' @param graph The input graph.
#' @param directed logical scalar, whether to use directed shortest paths for
#' calculating betweenness.
#' @param nobigint Logical scalar, whether to use big integers for the
#' betweenness calculation. This argument is passed to the
#' \code{\link{betweenness}} function.
#' @param normalized Logical scalar. Whether to normalize the graph level
#' centrality score by dividing by the theoretical maximum.
#' @return A named list with the following components:
#' \item{res}{The node-level centrality scores.}
#' \item{centralization}{The graph level centrality index.}
#' \item{theoretical_max}{The maximum theoretical graph level
#' centralization score for a graph with the given number of vertices,
#' using the same parameters. If the \code{normalized} argument was
#' \code{TRUE}, then the result was divided by this number.}
#'
#' @aliases centralization.betweenness
#' @family centralization related
#'
#' @export
#'
#' @examples
#' # A BA graph is quite centralized
#' g <- sample_pa(1000, m = 4)
#' centr_degree(g)$centralization
#' centr_clo(g, mode = "all")$centralization
#' centr_betw(g, directed = FALSE)$centralization
#' centr_eigen(g, directed = FALSE)$centralization
centr_betw <- centr_betw
#' Theoretical maximum for betweenness centralization
#'
#' See \code{\link{centralize}} for a summary of graph centralization.
#'
#' @param graph The input graph. It can also be \code{NULL}, if
#' \code{nodes} is given.
#' @param nodes The number of vertices. This is ignored if the graph is
#' given.
#' @param directed logical scalar, whether to use directed shortest paths
#' for calculating betweenness.
#' @return Real scalar, the theoratical maximum (unnormalized) graph
#' betweenness centrality score for graphs with given order and other
#' parameters.
#'
#' @aliases centralization.betweenness.tmax
#' @family centralization related
#'
#' @export
#'
#' @examples
#' # A BA graph is quite centralized
#' g <- sample_pa(1000, m = 4)
#' centr_betw(g, normalized = FALSE)$centralization %>%
#' `/`(centr_betw_tmax(g))
#' centr_betw(g, normalized = TRUE)$centralization
centr_betw_tmax <- centr_betw_tmax
#' Centralize a graph according to the closeness of vertices
#'
#' See \code{\link{centralize}} for a summary of graph centralization.
#'
#' @param graph The input graph.
#' @param mode This is the same as the \code{mode} argument of
#' \code{closeness}.
#' @param normalized Logical scalar. Whether to normalize the graph level
#' centrality score by dividing by the theoretical maximum.
#' @return A named list with the following components:
#' \item{res}{The node-level centrality scores.}
#' \item{centralization}{The graph level centrality index.}
#' \item{theoretical_max}{The maximum theoretical graph level
#' centralization score for a graph with the given number of vertices,
#' using the same parameters. If the \code{normalized} argument was
#' \code{TRUE}, then the result was divided by this number.}
#'
#' @aliases centralization.closeness
#' @family centralization related
#'
#' @export
#'
#' @examples
#' # A BA graph is quite centralized
#' g <- sample_pa(1000, m = 4)
#' centr_degree(g)$centralization
#' centr_clo(g, mode = "all")$centralization
#' centr_betw(g, directed = FALSE)$centralization
#' centr_eigen(g, directed = FALSE)$centralization
centr_clo <- centr_clo
#' Theoretical maximum for closeness centralization
#'
#' See \code{\link{centralize}} for a summary of graph centralization.
#'
#' @param graph The input graph. It can also be \code{NULL}, if
#' \code{nodes} is given.
#' @param nodes The number of vertices. This is ignored if the graph is
#' given.
#' @param mode This is the same as the \code{mode} argument of
#' \code{closeness}.
#' @return Real scalar, the theoratical maximum (unnormalized) graph
#' closeness centrality score for graphs with given order and other
#' parameters.
#'
#' @aliases centralization.closeness.tmax
#' @family centralization related
#'
#' @export
#'
#' @examples
#' # A BA graph is quite centralized
#' g <- sample_pa(1000, m = 4)
#' centr_clo(g, normalized = FALSE)$centralization %>%
#' `/`(centr_clo_tmax(g))
#' centr_clo(g, normalized = TRUE)$centralization
centr_clo_tmax <- centr_clo_tmax
#' Centralize a graph according to the eigenvector centrality of vertices
#'
#' See \code{\link{centralize}} for a summary of graph centralization.
#'
#' @param graph The input graph.
#' @param directed logical scalar, whether to use directed shortest paths for
#' calculating eigenvector centrality.
#' @param scale Whether to rescale the eigenvector centrality scores, such that
#' the maximum score is one.
#' @param options This is passed to \code{\link{eigen_centrality}}, the options
#' for the ARPACK eigensolver.
#' @param normalized Logical scalar. Whether to normalize the graph level
#' centrality score by dividing by the theoretical maximum.
#' @return A named list with the following components:
#' \item{vector}{The node-level centrality scores.}
#' \item{value}{The corresponding eigenvalue.}
#' \item{options}{ARPACK options, see the return value of
#' \code{\link{eigen_centrality}} for details.}
#' \item{centralization}{The graph level centrality index.}
#' \item{theoretical_max}{The same as above, the theoretical maximum
#' centralization score for a graph with the same number of vertices.}
#'
#' @aliases centralization.evcent
#' @family centralization related
#'
#' @export
#'
#' @examples
#' # A BA graph is quite centralized
#' g <- sample_pa(1000, m = 4)
#' centr_degree(g)$centralization
#' centr_clo(g, mode = "all")$centralization
#' centr_betw(g, directed = FALSE)$centralization
#' centr_eigen(g, directed = FALSE)$centralization
#'
#' # The most centralized graph according to eigenvector centrality
#' g0 <- make_graph(c(2,1), n = 10, dir = FALSE)
#' g1 <- make_star(10, mode = "undirected")
#' centr_eigen(g0)$centralization
#' centr_eigen(g1)$centralization
centr_eigen <- centr_eigen
#' Theoretical maximum for betweenness centralization
#'
#' See \code{\link{centralize}} for a summary of graph centralization.
#'
#' @param graph The input graph. It can also be \code{NULL}, if
#' \code{nodes} is given.
#' @param nodes The number of vertices. This is ignored if the graph is
#' given.
#' @param directed logical scalar, whether to use directed shortest paths
#' for calculating betweenness.
#' @param scale Whether to rescale the eigenvector centrality scores,
#' such that the maximum score is one.
#' @return Real scalar, the theoratical maximum (unnormalized) graph
#' betweenness centrality score for graphs with given order and other
#' parameters.
#'
#' @aliases centralization.evcent.tmax
#' @family centralization related
#'
#' @export
#'
#' @examples
#' # A BA graph is quite centralized
#' g <- sample_pa(1000, m = 4)
#' centr_eigen(g, normalized = FALSE)$centralization %>%
#' `/`(centr_eigen_tmax(g))
#' centr_eigen(g, normalized = TRUE)$centralization
centr_eigen_tmax <- centr_eigen_tmax
|