% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/topic_modeling.R
\name{get_topic_prevalence}
\alias{get_topic_prevalence}
\title{Get Topic Prevalence (Gamma) from STM Model}
\usage{
get_topic_prevalence(stm_model, category = NULL, include_theta = FALSE)
}
\arguments{
\item{stm_model}{A fitted STM model object from stm::stm().}

\item{category}{Optional character string to add as a category column.}

\item{include_theta}{Logical, if TRUE includes document-topic matrix (default: FALSE).}
}
\value{
A data frame with columns:
\item{topic}{Topic number}
\item{gamma}{Mean topic prevalence across documents}
\item{category}{Category label (if provided)}
}
\description{
Extracts topic prevalence values (gamma/theta) from a fitted STM model,
returning mean prevalence for each topic as a data frame.
}
\examples{
if (interactive() && requireNamespace("stm", quietly = TRUE)) {
  # Requires fitting an STM model first; uses 'stm::gadarian' for demo
  data("gadarian", package = "stm")
  proc <- stm::textProcessor(gadarian$open.ended.response, metadata = gadarian)
  prep <- stm::prepDocuments(proc$documents, proc$vocab, proc$meta)
  topic_model <- stm::stm(prep$documents, prep$vocab, K = 3,
                           data = prep$meta, max.em.its = 5,
                           verbose = FALSE)
  prevalence <- get_topic_prevalence(topic_model)
  prevalence_label <- get_topic_prevalence(topic_model, category = "demo")
}
}
\concept{topic-modeling}
