This function can be used on the output of qgraph to compute the node centrality statistics for weighted graphs proposed by Opsahl, Agneessens and Skvoretz (2010).
centrality(graph, alpha = 1, posfun = abs, pkg = c("igraph","qgraph"),
all.shortest.paths = FALSE, weighted = TRUE, signed = TRUE, R2 = FALSE)A list containing:
A vector containing the outward degree of each node.
A vector containing the inward degree of each node.
A vector containing the closeness of each node.
A vector containing the betweenness of each node.
Expected incoming influence - sum of incoming edge weights connected to a node (not made absolute)
Expected outgoing influence - sum of outgoing edge weights connected to a node (not made absolute)
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 raised to the power alpha.
A matrix of lists containing all shortest paths between all pairs of nodes. Use double square brackets to index. E.g., if the list is called 'res', res$ShortestPaths[[i,j]] gives a list containing all shortest paths between node i and j. With pkg = "igraph", shortest paths are only returned if all.shortest.paths = TRUE.
Only if R2 = TRUE: a vector containing the predictability (R-squared) of each node.
A "qgraph" object obtained from qgraph
The tuning parameter. Defaults to 1.
A function that converts positive and negative values to only positive. Defaults to the absolute value.
Package to use. Either "igraph" or "qgraph". Defaults to "igraph".
Logical if all shortest paths should be returned. Defaults to FALSE. Setting this to true can greatly increase computing time if pkg = "igraph".
Logical, set to FALSE to set all edge weights to 1 or -1
Logical, set to FALSE to make all edge weights absolute
Logical, should R-squared (predictability) be computed for GGM structures?
Sacha Epskamp (mail@sachaepskamp.com)
This function computes and returns the in and out degrees, closeness and betweenness as well as the shortest path lengths and shortest paths between all pairs of nodes in the graph. For more information on these statistics, see Opsahl, Agneessens and Skvoretz (2010).
Self-loops are ignored in computing centrality indices. These statistics are only defined for positive edge weights, and thus negative edge weights need to be transformed into positive edge weights. By default, this is done by taking the absolute value.
The shortest paths are computed using Dijkstra's algorithm (Dijkstra, 1959).
Opsahl, T., Agneessens, F., Skvoretz, J. (2010). Node centrality in weighted networks: generalizing degree and shortest paths. Soc Netw. 32:245–251.
Dijkstra, E.W. (1959). A note on two problems in connexion with graphs. Numerische Mathematik 1, 269–271.
qgraph
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(Q)
Run the code above in your browser using DataLab