% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/centrality_stability.R
\name{centrality_stability}
\alias{centrality_stability}
\title{Centrality Stability Coefficient (CS-coefficient)}
\usage{
centrality_stability(
  x,
  measures = c("InStrength", "OutStrength", "Betweenness"),
  iter = 1000L,
  drop_prop = seq(0.1, 0.9, by = 0.1),
  threshold = 0.7,
  certainty = 0.95,
  method = "pearson",
  centrality_fn = NULL,
  loops = FALSE,
  normalize = FALSE,
  invert = TRUE,
  normalize_diffusion = TRUE,
  seed = NULL
)
}
\arguments{
\item{x}{A \code{netobject} from \code{\link{build_network}}.}

\item{measures}{Character vector. Centrality measures to assess.
Defaults to \code{c("InStrength", "OutStrength", "Betweenness")}. Pass
\code{"all"} for every built-in measure: \code{"OutStrength"},
\code{"InStrength"}, \code{"ClosenessIn"}, \code{"ClosenessOut"},
\code{"Closeness"}, \code{"Betweenness"}, \code{"BetweennessRSP"},
\code{"Diffusion"}, and \code{"Clustering"}. The legacy aliases
\code{"InCloseness"} and \code{"OutCloseness"} are also accepted. Custom
measures beyond these are valid only when a \code{centrality_fn} is
supplied to resolve them.}

\item{iter}{Integer. Number of bootstrap iterations per drop
proportion (default: 1000).}

\item{drop_prop}{Numeric vector. Proportions of cases to drop
(default: \code{seq(0.1, 0.9, by = 0.1)}).}

\item{threshold}{Numeric. Minimum correlation to consider stable
(default: 0.7).}

\item{certainty}{Numeric. Required proportion of iterations above
threshold (default: 0.95).}

\item{method}{Character. Correlation method: \code{"pearson"},
\code{"spearman"}, or \code{"kendall"} (default: \code{"pearson"}).}

\item{centrality_fn}{Optional function. A custom centrality function
that takes a weight matrix and returns a named list of centrality
vectors. When \code{NULL} (default), all built-in measures are
computed internally: \code{"InStrength"}/\code{"OutStrength"} via
\code{colSums}/\code{rowSums}, and \code{"Betweenness"}/
\code{"InCloseness"}/\code{"OutCloseness"}/\code{"Closeness"} via an
internal Floyd-Warshall shortest-path routine. When provided, the
function is called as \code{centrality_fn(mat)} and is used only for
requested measures that are not one of the six built-ins; it should
return a named list (e.g., \code{list(my_metric = ...)}).}

\item{loops}{Logical. If \code{FALSE} (default), self-loops (diagonal)
are excluded from centrality computation. This does not modify the
stored matrix.}

\item{normalize}{Logical. Range-normalize all requested measures using the
same transformation as \code{tna::centralities(normalize = TRUE)}.
Default: \code{FALSE}.}

\item{invert}{Logical. Invert weights for shortest-path measures?
Default: \code{TRUE}, matching \code{tna}.}

\item{normalize_diffusion}{Logical. Range-normalize \code{Diffusion} even
when \code{normalize = FALSE}. Default: \code{TRUE}.}

\item{seed}{Integer or NULL. RNG seed for reproducibility.}
}
\value{
An object of class \code{"net_stability"} containing:
\describe{
\item{cs}{Named numeric vector of CS-coefficients per measure.}
\item{correlations}{Named list of matrices (iter x n_prop) of
correlation values per measure.}
\item{measures}{Character vector of measures assessed.}
\item{drop_prop}{Drop proportions used.}
\item{threshold}{Stability threshold.}
\item{certainty}{Required certainty level.}
\item{iter}{Number of iterations.}
\item{method}{Correlation method.}
}
}
\description{
Estimates the stability of centrality indices under case-dropping.
For each drop proportion, sequences are randomly removed and the
network is re-estimated. The correlation between the original and
subset centrality values is computed. The CS-coefficient is the
maximum proportion of cases that can be dropped while maintaining
a correlation above \code{threshold} in at least \code{certainty}
of bootstrap samples.

For transition methods, uses pre-computed per-sequence count matrices
for fast resampling. Strength centralities (InStrength, OutStrength)
are computed directly from the matrix without igraph.
}
\examples{
net <- build_network(data.frame(V1 = c("A","B","C","A"),
  V2 = c("B","C","A","B")), method = "relative")
cs <- centrality_stability(net, iter = 10, drop_prop = 0.3)
\donttest{
seqs <- data.frame(
  V1 = sample(LETTERS[1:4], 30, TRUE), V2 = sample(LETTERS[1:4], 30, TRUE),
  V3 = sample(LETTERS[1:4], 30, TRUE), V4 = sample(LETTERS[1:4], 30, TRUE)
)
net <- build_network(seqs, method = "relative")
cs <- centrality_stability(net, iter = 100, seed = 42,
  measures = c("InStrength", "OutStrength"))
print(cs)
}

}
\seealso{
\code{\link{build_network}}, \code{\link{network_reliability}}
}
