Skip to contents

The share of each topic's word distribution that falls on vocabulary terms matching a pattern (\(\sum_{v \in S} \beta_{kv}\)), e.g. to find the topics about the environment with "climat|green|environment". A sum rather than a mean: a topic with many matching words scores higher than a topic with one.

Usage

topic_word_mass(model, regex, n_terms = 5L, ...)

Arguments

model

A fitted stm model (or a list with beta$logbeta[[1]] and vocab).

regex

Regular expression (ICU, via stringi) matched against the vocabulary; several patterns are joined by |. In the vocabulary built by extract_ngrams(), the words of an n-gram are joined by _ ("green_bond"). A space in regex is therefore replaced by _, with a warning.

n_terms

Integer scalar, number of matching terms listed per topic.

...

Not used: an argument renamed in the development version of mintR gives an error naming its replacement.

Value

A data.table with topic, mass and top_terms (the most probable matching terms), by decreasing mass.

Examples

logbeta <- log(matrix(c(0.5, 0.3, 0.2, 0.1, 0.2, 0.7), nrow = 2, byrow = TRUE))
mdl <- list(beta = list(logbeta = list(logbeta)), vocab = c("green_bond", "labour", "climate"))
topic_word_mass(mdl, "green|climat")
#>    topic  mass           top_terms
#>    <int> <num>              <char>
#> 1:     2   0.8 climate, green_bond
#> 2:     1   0.7 green_bond, climate