Performs a targeted attack or random failure analysis on a network, calculating the size of the largest connected component after sequential vertex or edge removal.
In a targeted attack, vertices are sorted by degree or betweenness centrality (or edges by betweenness), and successively removed from highest to lowest. In a random failure analysis, vertices/edges are removed in random order.
robustness(
x,
type = c("vertex", "edge"),
measure = c("betweenness", "degree", "random"),
strategy = c("sequential", "static"),
n_iter = 1000,
mode = "all",
seed = NULL,
...
)A data frame (class "cograph_robustness") with one row per removal
step, from zero removed through all removed (n + 1 rows, where
n is the number of vertices or edges), and columns:
Fraction of vertices/edges removed (0 to 1)
Size of largest component after removal (averaged over
n_iter runs when measure = "random")
Ratio of component size to original maximum
The measure argument: "betweenness", "degree", or
"random"
A human-readable label for the analysis, one of
"Targeted vertex attack", "Targeted edge attack",
"Random vertex removal" or "Random edge removal" - not the bare
type argument
The original number of vertices/edges ("n_original") and the original
largest-component size ("orig_max") are stored as attributes.
Network input: matrix, igraph, network, cograph_network, or tna object
Character string; either "vertex" or "edge" removals. Default: "vertex"
Character string; sort by "betweenness", "degree", or "random". Default: "betweenness"
Character string; "sequential" (default) recalculates centrality after each removal. "static" computes centrality once on the original network and removes nodes in that fixed order (brainGraph-style). Only affects targeted attacks; random removal is unaffected.
Integer; number of iterations for random analysis. Default: 1000 (matching brainGraph convention)
For directed networks: "all", "in", or "out". Default "all".
Random seed for reproducibility. Default NULL.
Passed to to_igraph, whose only other argument
is directed; anything else raises an "unused argument" error.
Three attack strategies are available:
Targeted Attack - Betweenness (default): Vertices/edges are sorted by betweenness centrality and removed from highest to lowest. This targets nodes that bridge different network regions.
Targeted Attack - Degree: Vertices are sorted by degree and removed from highest to lowest. This targets highly connected hub nodes. Note: for edge attacks, degree is not available; use betweenness instead.
Random Failure: Vertices/edges are removed in random order, averaged over n_iter iterations. This simulates random component failures.
Strategy:
The strategy parameter controls how targeted attacks work:
"sequential" (default): Recalculates centrality after each
removal. This is a stronger attack because removing a hub changes which
nodes become the new bridges/hubs.
"static": Computes centrality once on the original network and
removes nodes in that fixed order (as in brainGraph). This matches the
original Albert et al. (2000) method.
Scale-free networks are typically robust to random failures but vulnerable to targeted attacks, while random networks degrade more uniformly.
Albert, R., Jeong, H., & Barabasi, A.L. (2000). Error and attack tolerance of complex networks. Nature, 406, 378-381. tools:::Rd_expr_doi("10.1038/35019019")
plot_robustness, robustness_auc
# Create a scale-free network
if (requireNamespace("igraph", quietly = TRUE)) {
g <- igraph::sample_pa(50, m = 2, directed = FALSE)
# Targeted attack by betweenness
rob_btw <- robustness(g, measure = "betweenness")
# Targeted attack by degree
rob_deg <- robustness(g, measure = "degree")
# Random failure
rob_rnd <- robustness(g, measure = "random", n_iter = 50)
# View results
head(rob_btw)
}
Run the code above in your browser using DataLab