% 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,
  seed = NULL
)
}
\arguments{
\item{x}{A \code{netobject} from \code{\link{build_network}}.}

\item{measures}{Character vector. Centrality measures to assess.
Built-in: \code{"InStrength"}, \code{"OutStrength"}, \code{"Betweenness"},
\code{"InCloseness"}, \code{"OutCloseness"}, \code{"Closeness"}.
Custom measures beyond these require \code{centrality_fn}.
Default: \code{c("InStrength", "OutStrength", "Betweenness")}.}

\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), only \code{"InStrength"} and
\code{"OutStrength"} are computed via \code{colSums}/\code{rowSums}.
When provided, the function is called as \code{centrality_fn(mat)}
and should return a named list (e.g.,
\code{list(Betweenness = ..., Closeness = ...)}).}

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

\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}}
}
