% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/topic_modeling.R
\name{assess_embedding_stability}
\alias{assess_embedding_stability}
\title{Assess Embedding Topic Model Stability}
\usage{
assess_embedding_stability(
  texts,
  n_runs = 5,
  embedding_model = "all-MiniLM-L6-v2",
  select_best = TRUE,
  base_seed = 123,
  verbose = TRUE,
  ...
)
}
\arguments{
\item{texts}{Character vector of documents to analyze.}

\item{n_runs}{Number of model runs with different seeds (default: 5).
More runs give a steadier stability estimate.}

\item{embedding_model}{Embedding model name (default: "all-MiniLM-L6-v2").}

\item{select_best}{Logical, if TRUE, returns the best model by quality (default: TRUE).}

\item{base_seed}{Base random seed; each run uses base_seed + (run - 1).}

\item{verbose}{Logical, if TRUE, prints progress messages.}

\item{...}{Additional arguments passed to fit_embedding_model().}
}
\value{
A list containing:
\itemize{
\item stability_metrics: List with mean_ari, sd_ari, mean_jaccard, quality_variance
\item best_model: Best model by silhouette score (if select_best = TRUE)
\item all_models: List of all fitted models
\item is_stable: Logical, TRUE if mean ARI >= 0.6 (considered stable)
\item recommendation: Text recommendation based on stability
}
}
\description{
Evaluates the stability of embedding-based topic modeling by running multiple models
with different random seeds and comparing their results. High stability (high ARI,
consistent keywords) indicates stable topic structure in the data.
}
\details{
Stability is assessed via:
\itemize{
\item Adjusted Rand Index (ARI): Measures agreement in topic assignments across runs
\item Keyword Jaccard similarity: Measures overlap in top keywords per topic
\item Quality variance: Variance in silhouette scores across runs
}
}
\examples{
if (interactive()) {
  texts <- c("Machine learning for image recognition",
             "Deep learning neural networks",
             "Natural language processing models")

  stability <- assess_embedding_stability(
    texts = texts,
    n_runs = 3,
    verbose = TRUE
  )

  # Check if results are stable
  stability$is_stable
  stability$stability_metrics$mean_ari

  # Use the best model
  best_model <- stability$best_model
}
}
\concept{topic-modeling}
