
Create a Table for Per-Document Per-Topic Probabilities
Source:R/text_mining_functions.R
topic_probability_table.Rd
This function generates a table of mean topic prevalence across all documents.
Arguments
- stm_model
A fitted STM model object.
- top_n
The number of topics to display, ordered by their mean prevalence.
- verbose
Logical, if TRUE, prints progress messages.
- ...
Further arguments passed to
tidytext::tidy
.
Value
A tibble
containing columns topic
and gamma
, where topic
is a factor representing each topic (relabeled with a "Topic X" format), and gamma
is the
mean topic prevalence across all documents. Numeric values are rounded to three decimal places.
Examples
if (interactive()) {
df <- TextAnalysisR::SpecialEduTech
united_tbl <- TextAnalysisR::unite_text_cols(df, listed_vars = c("title", "keyword", "abstract"))
tokens <- TextAnalysisR::preprocess_texts(united_tbl, text_field = "united_texts")
dfm_object <- quanteda::dfm(tokens)
out <- quanteda::convert(dfm_object, to = "stm")
stm_15 <- stm::stm(
data = out$meta,
documents = out$documents,
vocab = out$vocab,
max.em.its = 75,
init.type = "Spectral",
K = 15,
prevalence = ~ reference_type + s(year),
verbose = TRUE)
topic_probability_table <- TextAnalysisR::topic_probability_table(
stm_model= stm_15,
top_n = 10,
verbose = TRUE)
print(topic_probability_table)
}