Skip to contents

Extracts topic prevalence values (gamma/theta) from a fitted STM model, returning mean prevalence for each topic as a data frame.

Usage

get_topic_prevalence(stm_model, category = NULL, include_theta = FALSE)

Arguments

stm_model

A fitted STM model object from stm::stm().

category

Optional character string to add as a category column.

include_theta

Logical, if TRUE includes document-topic matrix (default: FALSE).

Value

A data frame with columns:

topic

Topic number

gamma

Mean topic prevalence across documents

category

Category label (if provided)

Examples

if (FALSE) { # \dontrun{
# Fit STM model
topic_model <- stm::stm(documents, vocab, K = 10)

# Get topic prevalence
prevalence <- get_topic_prevalence(topic_model)

# With category label
prevalence_sld <- get_topic_prevalence(topic_model, category = "SLD")
} # }