% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/robustness.R
\name{robustness}
\alias{robustness}
\title{Network Robustness Analysis}
\usage{
robustness(
  x,
  type = c("vertex", "edge"),
  measure = c("betweenness", "degree", "random"),
  strategy = c("sequential", "static"),
  n_iter = 1000,
  mode = "all",
  seed = NULL,
  ...
)
}
\arguments{
\item{x}{Network input: matrix, igraph, network, cograph_network, or tna object}

\item{type}{Character string; either "vertex" or "edge" removals. Default: "vertex"}

\item{measure}{Character string; sort by "betweenness", "degree", or "random".
Default: "betweenness"}

\item{strategy}{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.}

\item{n_iter}{Integer; number of iterations for random analysis. Default: 1000
(matching brainGraph convention)}

\item{mode}{For directed networks: "all", "in", or "out". Default "all".}

\item{seed}{Random seed for reproducibility. Default NULL.}

\item{...}{Additional arguments passed to \code{\link{to_igraph}}}
}
\value{
A data frame (class "cograph_robustness") with columns:
\describe{
\item{removed_pct}{Fraction of vertices/edges removed (0 to 1)}
\item{comp_size}{Size of largest component after removal}
\item{comp_pct}{Ratio of component size to original maximum}
\item{measure}{Attack strategy used}
\item{type}{Type of analysis (vertex or edge removal)}
}
}
\description{
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.
}
\details{
Three attack strategies are available:

\strong{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.

\strong{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.

\strong{Random Failure:}
Vertices/edges are removed in random order, averaged over n_iter iterations.
This simulates random component failures.

\strong{Strategy:}
The \code{strategy} parameter controls how targeted attacks work:
\itemize{
\item \code{"sequential"} (default): Recalculates centrality after each
removal. This is a stronger attack because removing a hub changes which
nodes become the new bridges/hubs.
\item \code{"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.
}
\examples{
# 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)
}

}
\references{
Albert, R., Jeong, H., & Barabasi, A.L. (2000). Error and attack tolerance
of complex networks. \emph{Nature}, 406, 378-381.
\doi{10.1038/35019019}
}
\seealso{
\code{\link{plot_robustness}}, \code{\link{robustness_auc}}
}
