Skip to contents

In an STM with a content covariate (for instance the type of document: article, report, speech), a topic does not have one list of words but one per level of the covariate: the same topic is expressed with different words in an article and in a report. The fitted model then stores one word distribution per level (model$beta$logbeta is a list of matrices), and stm::labelTopics() and the other functions of this package, which expect a single distribution per topic, cannot read it (they stop with an error pointing here).

marginal_topic_model() returns a copy of the model with a single distribution per topic, the average of the levels' distributions. Use it before topic_labels(), topic_terms(), topic_word_mass() or the metrics, to describe each topic with its words across all document types. Each level counts in proportion to the number of tokens of the documents that belong to it, so that a type with few documents weighs little:

$$\beta_{kv} = \sum_{a} \pi_{a} \, \beta_{kv}^{a}$$

where \(\beta_{kv}^{a}\) is the probability of word \(v\) in topic \(k\) for level \(a\), and \(\pi_{a}\) is the share of the corpus tokens that are in documents of level \(a\).

Usage

marginal_topic_model(model, documents, content, ...)

Arguments

model

A fitted stm model.

documents

The model's documents (stm_data$documents).

content

Vector of the content covariate, one value per document (e.g. stm_data$meta$doc_type).

...

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

Value

An stm model with one word distribution per topic. A model without content covariate is returned unchanged.