| centrality | R Documentation |
Computes centrality measures for nodes in a network and returns a tidy data frame. Accepts matrices, igraph objects, cograph_network, or tna objects.
centrality(
x,
type = c("basic", "extended", "all"),
measures = NULL,
mode = "all",
normalized = FALSE,
weighted = TRUE,
directed = NULL,
loops = TRUE,
simplify = "sum",
digits = NULL,
sort_by = NULL,
cutoff = -1,
invert_weights = NULL,
alpha = 1,
damping = 0.85,
personalized = NULL,
transitivity_type = "local",
isolates = "nan",
lambda = 1,
diffusion_method = NULL,
k = 3,
states = NULL,
decay_parameter = 0.5,
dmnc_epsilon = 1.7,
membership = NULL,
katz_alpha = 0.1,
hubbell_weight = 0.5,
tna_network = NULL,
psych_network = NULL,
...
)
x |
Network input (matrix, igraph, network, cograph_network, tna object) |
type |
Character scalar selecting a curated tier of measures when
Passing |
measures |
Character vector of specific measure names to compute.
When |
mode |
For directed networks: "all", "in", or "out". Affects measures whose output columns carry a mode suffix, including degree, strength, closeness, eccentricity, coreness, harmonic, diffusion, leverage, k-reach, distance-based measures, community-aware measures, and expected influence. |
normalized |
Logical. Normalize values by dividing by max. Most measures are scaled to 0-1; signed expected-influence measures can retain negative values under psychometric normalization. For closeness, this is passed directly to igraph. |
weighted |
Logical. Use edge weights if available. Default TRUE. |
directed |
Logical or NULL. If NULL (default), auto-detect from matrix symmetry. Set TRUE to force directed, FALSE to force undirected. |
loops |
Logical. If TRUE (default), keep self-loops. Set to FALSE to remove them before calculation. |
simplify |
How to combine multiple edges between the same node pair. Options: "sum" (default), "mean", "max", "min", or FALSE/"none" to keep multiple edges. |
digits |
Integer or NULL. Round all numeric columns to this many decimal places. Default NULL (no rounding). |
sort_by |
Character or NULL. Column name to sort results by (descending order). Default NULL (original node order). |
cutoff |
Maximum path length to consider for betweenness, closeness, and harmonic centrality. Default -1 (no limit). Set to a positive value for faster computation on large networks at the cost of accuracy. |
invert_weights |
Logical or NULL. For path- and distance-based measures (for example betweenness, closeness, harmonic, eccentricity, k-reach, radiality, decay, stress, flow betweenness, and related variants), should weights be inverted so that higher weights mean shorter paths? Default NULL auto-detects: TRUE for tna objects (transition probabilities), FALSE otherwise (matching igraph/sna). Set explicitly to TRUE for strength/frequency weights (qgraph style) or FALSE for distance/cost weights. |
alpha |
Numeric. Exponent for weight transformation when |
damping |
PageRank damping factor. Default 0.85. Must be between 0 and 1. |
personalized |
Named numeric vector for personalized PageRank. Default NULL (standard PageRank). Values should sum to 1. |
transitivity_type |
Type of transitivity to calculate: "local" (default),
"global", "undirected", "localundirected", "barrat" (weighted),
"weighted", or "onnela". The first six dispatch to
|
isolates |
How to handle isolate nodes in transitivity calculation: "nan" (default) returns NaN, "zero" returns 0. |
lambda |
Diffusion scaling factor for diffusion centrality. Default 1.
Only used when |
diffusion_method |
Character or NULL. Selects the diffusion-centrality
formula. |
k |
Path length parameter for geodesic k-path centrality. Default 3. |
states |
Named numeric vector of percolation states (0-1) for percolation centrality. Each value represents how "activated" or "infected" a node is. Default NULL (all nodes get state 1, equivalent to betweenness). |
decay_parameter |
Numeric. Decay parameter for decay and generalized closeness centrality. Default 0.5. Must be between 0 and 1. |
dmnc_epsilon |
Numeric. Epsilon exponent for DMNC (Density of Maximum Neighborhood Component). Default 1.7 as recommended by Lin et al. (2008). centiserve uses 1.67 (four-community assumption). Must be between 1 and 2. |
membership |
Integer vector of community assignments (one per node) for community-aware measures: participation, within_module_z, gateway, and the Gould-Fernandez brokerage roles. Default NULL. Required when requesting these measures. |
katz_alpha |
Attenuation factor for Katz centrality. Must satisfy
|
hubbell_weight |
Weight factor |
tna_network |
Logical or NULL. Umbrella switch that forces tna-style
conventions across all measures. |
psych_network |
Logical or NULL. Switch for signed psychometric
network conventions. |
... |
Additional arguments (currently unused) |
The following centrality measures are available:
Count of edges (supports mode: in/out/all)
Weighted degree (supports mode: in/out/all)
Shortest path centrality
Inverse distance centrality (supports mode: in/out/all)
Influence-based centrality
Random walk centrality (supports damping and personalization)
HITS authority score
HITS hub score
Maximum distance to other nodes (supports mode)
K-core membership (supports mode: in/out/all)
Burt's constraint (structural holes)
Local clustering coefficient (supports multiple types)
Harmonic centrality - handles disconnected graphs better than closeness (supports mode: in/out/all)
Diffusion degree centrality - sum of scaled degrees of node and its neighbors (supports mode: in/out/all, lambda scaling)
Leverage centrality - measures influence over neighbors based on relative degree differences (supports mode: in/out/all)
Geodesic k-path centrality - count of nodes reachable within distance k (supports mode: in/out/all, k parameter)
Alpha/Katz centrality - influence via paths, penalized by distance. Similar to eigenvector but includes exogenous contribution
Bonacich power centrality - measures influence based on connections to other influential nodes
Subgraph centrality - participation in closed loops/walks, weighting shorter loops more heavily
Laplacian centrality using Qi et al. (2012) local formula. Matches NetworkX and centiserve::laplacian()
Load centrality - fraction of all shortest paths through node, similar to betweenness but weights paths by 1/count
Information centrality - closeness based on electrical current flow (requires connected graph)
Random walk betweenness - betweenness based on current flow rather than shortest paths (requires connected graph)
VoteRank - identifies influential spreaders via iterative voting mechanism. Returns normalized rank (1 = most influential)
Percolation centrality - importance for spreading processes. Uses node states (0-1) to weight paths. When all states equal, equivalent to betweenness. Useful for epidemic/information spreading analysis.
Radiality centrality (centiserve). Sum of (diam + 1 - d) normalized by n-1.
Lin's centrality. Reachable nodes squared divided by sum of distances.
Decay centrality. Sum of delta^d for parameter delta.
Residual closeness. Sum of 1/2^d.
Dangalchev closeness (alias for residual closeness).
Generalized closeness. Sum of alpha^d.
Harary centrality. Sum of 1/d^2 for all reachable pairs.
Average distance (centiserve). Sum of distances / (n+1).
Barycenter centrality. 1 / sum of distances.
Wiener index. Total sum of shortest path distances from node.
Closeness vitality. Drop in Wiener index when node removed.
Total communicability. Row sums of matrix exponential.
Communicability betweenness. Fraction of communicability through each node.
Random walk centrality. Inverse sum of random walk distances (requires connected graph).
Stress centrality. Number of shortest paths through node.
Flow betweenness. Max-flow based betweenness.
Lobby index (h-index of neighborhood).
Graph entropy centrality. Entropy change on node removal.
Semi-local centrality. Triple-nested neighborhood sum.
ClusterRank. Clustering coefficient times neighbor degree sum.
Bottleneck centrality. Count of shortest path trees where node is critical.
Centroid value. Minimum f(v,i) across all nodes.
Maximum Neighborhood Component size.
Density of Maximum Neighborhood Component.
Topological coefficient. Shared neighbor ratio.
Bridging centrality. Betweenness times bridging coefficient.
Local bridging. (1/degree) times bridging coefficient.
Burt's effective size. Degree minus redundancy.
Diversity centrality. Shannon entropy of edge weight distribution.
Cross-clique connectivity. Count of cliques containing node.
Markov centrality. Inverse mean first passage time (requires connected graph).
Integration centrality. Distance-based influence.
Expected centrality. Sum of neighbor degrees.
Gil-Schmidt power index. Sum of 1/d normalized by n-1.
SALSA authority scores (directed graphs only).
LeaderRank. PageRank with ground node (directed graphs only).
Participation coefficient. Diversity of inter-community
connections (requires membership).
Within-module degree z-score. Intra-community
connectivity (requires membership).
Gateway coefficient. Inter-community brokerage weighted by
centrality (requires membership).
A data frame with columns:
node: Node labels/names
One column per measure, with mode suffix for directional measures
(e.g., degree_in, closeness_all)
# Basic usage with matrix
adj <- matrix(c(0, 1, 1, 1, 0, 1, 1, 1, 0), 3, 3)
rownames(adj) <- colnames(adj) <- c("A", "B", "C")
centrality(adj)
# Specific measures
centrality(adj, measures = c("degree", "betweenness"))
# Directed network with normalization
centrality(adj, mode = "in", normalized = TRUE)
# Sort by pagerank
centrality(adj, sort_by = "pagerank", digits = 3)
# PageRank with custom damping
centrality(adj, measures = "pagerank", damping = 0.9)
# Harmonic centrality (better for disconnected graphs)
centrality(adj, measures = "harmonic")
# Global transitivity
centrality(adj, measures = "transitivity", transitivity_type = "global")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.