This function can be used on several kinds of graphs to compute several node centrality statistics and the edge-betweenness centrality. The input graph can be an adjacency matrix, a weight matrix, an edgelist (weighted or unweighted), a qgraph object or an igraph object.
centrality_auto(x, weighted = TRUE, signed = TRUE, communities = NULL,
useCommunities = "all")A list containing:
A dataframe that includes the node centrality statistics. A subset of the following centrality indices is included, depending on the input network: Degree, InDegree, OutDegree, Strength, InStrength, OutStrength, Betweenness, Closeness, ExpectedInfluence, InExpectedInfluence, and OutExpectedInfluence. If communities is supplied, the bridge centrality statistics (Jones, Ma, & McNally, 2021; see bridgeCentrality) are included as well.
A matrix containing the shortest path lengths of each pair of nodes. These path lengths are based on the inverse of the absolute edge weights.
The edge betweenness centrality statistic (Newman & Girvan, 2004). Edges are ordered by their decreasing centrality.
A graph. Can be a qgraph object, an igraph object, an adjacency matrix, a weight matrix, an edgelist, or a weighted edgelist.
Logical, set to FALSE to set all edge weights to 1 or -1
Logical, set to FALSE to make all edge weights absolute
A community assignment of each node (see bridgeCentrality for supported formats). When supplied, the bridge centrality statistics of Jones, Ma and McNally (2021) are included in node.centrality. Defaults to NULL, in which case no bridge centrality statistics are computed.
A character vector specifying which communities should be included in the computation of bridge centrality. Defaults to "all". See bridgeCentrality.
Giulio Costantini (giulio.costantini@unimib.it), Sacha Epskamp (mail@sachaepskamp.com)
The function recognizes whether the network is unweighted vs. weighted, undirected vs. directed, and connected vs. disconnected and computes a set of centrality indices that is best suited for that particular kind of network. Edge signs are disregarded in the computation of the shortest-path based indices (betweenness and closeness), while the expected influence statistics take edge signs into account (unless signed = FALSE, in which case all edge weights are made absolute). Edge weights and directions, if present, are considered in the computation of the indices. In undirected networks, the node betweenness centrality is divided by two. If the network is disconnected, closeness centrality is computed only considering the largest component (notice that this is different from what function centrality does).
If x is unweighted and directed, then the indegree, the outdegree, the node betweenness centrality, the closeness centrality, and the edge betweenness centrality are computed.
If x is unweighted and undirected, then the degree, the node betweenness centrality, the closeness centrality, and the edge betweenness centralities are computed.
If x is weighted and directed, then the instrength and the outstrength (same as indegree and outdegree, but considering weights), the node betweenness centrality, the closeness centrality, and edge betweenness centralities are computed.
If x is weighted and undirected, then the strength, the node betweenness centrality, the closeness centrality, and edge betweenness centralities are computed.
In all cases, the (in and out) expected influence statistics are computed as well.
Additionally, the shortest path length between each pair of nodes is also computed for all the kinds of networks.
Jones, P. J., Ma, R., & McNally, R. J. (2021). Bridge centrality: A network approach to understanding comorbidity. Multivariate Behavioral Research, 56(2), 353-367.
Newman, M. E. J., Girvan, M. (2004). Finding and evaluating community structure in networks. Physical Review E 69(026113).
Costantini, G., Epskamp, S., Borsboom, D., Perugini, M., Mõttus, R., Waldorp, L., Cramer, A. O. J., State of the aRt personality research: A tutorial on network analysis of personality data in R. Manuscript submitted for publication.
qgraph, centrality, bridgeCentrality
set.seed(1)
adj <- matrix(sample(0:1,10^2,TRUE,prob=c(0.8,0.2)),nrow=10,ncol=10)
Q <- qgraph(adj)
centrality_auto(Q)
# notice that a value NA is returned for the closeness centrality of nodes 3 and 9, which are not
# strongly connected to the largest component of the network (3 cannot reach other nodes, 9 cannot
# be reached).
Run the code above in your browser using DataLab