- Introduced by
- Margaret Roberts, Brandon Stewart & Dustin Tingley
- Year
- 2014
- Type
- Mixed-membership topic model with document-level covariates
- Family
- Topic modeling / text-as-data
What does it do?
The Structural Topic Model (STM) is a text-as-data method that discovers latent themes in a corpus while letting document metadata, such as party, time, gender, or treatment condition, shape those themes.
It extends correlated topic modeling so that topic prevalence (how much a document is about a topic) and topic content (the words used to express a topic) can both depend on covariates. Roberts, Stewart, Tingley and colleagues applied the model to open-ended survey responses in a 2014 article in the American Journal of Political Science, and the method estimates topics and covariate relationships jointly, with uncertainty.
The intuition behind the method
A plain topic model treats every document as an exchangeable bag of words and learns themes that have to explain the whole corpus at once. In political research, however, we usually know something about each document (who wrote it, when, and under what condition) and want to ask how the themes shift with those facts. STM builds that metadata into the model instead of assuming every document draws its topic mix from the same distribution. The expected mix can move with covariates, so documents from one party may give a topic more weight than documents from another, and the vocabulary of a topic can also change by group. Because the covariates are part of the model rather than added afterward, the estimated topic-covariate relationships carry uncertainty.
History
The structural topic model was introduced by Roberts, Stewart and Airoldi (2013), as cited in the 2014 American Journal of Political Science article by Roberts, Stewart, Tingley and colleagues. That article applied the model to open-ended survey responses and showed how document-level information, such as the author's gender, political affiliation, or treatment assignment, can be incorporated into the topics. Roberts, Stewart and Tingley (2019) documented the stm R package, which estimates the model by a fast variational approximation. The approach sits within Grimmer and Stewart's (2013) text-as-data agenda, which stresses that automated output requires extensive, problem-specific validation.
When to use it
Use STM when you have a corpus and document-level metadata and your research question is explicitly about how themes relate to that metadata — how topic emphasis differs by party, evolves over time, or responds to an experimental treatment. It is well suited to open-ended survey responses, legislative or media text, and any setting where you want topics and covariate effects estimated jointly with uncertainty. It is less appropriate when you have no meaningful covariates (a plain LDA or correlated topic model suffices), when you need a known dimension rather than emergent topics (text scaling fits better), or when the corpus is too small for stable topic estimation. As with all unsupervised methods, the topics require human validation.
Limitations and considerations
- Topics are still unsupervised and require human reading and validation; the model does not certify that a topic measures the intended construct.
- Results are sensitive to the number of topics K, to initialization, and to preprocessing, so the solution is not unique.
- Variational inference yields an approximation to the posterior, and reported uncertainty can understate true uncertainty.
- Adding content covariates greatly increases the parameter space and can make topics harder to estimate and interpret.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Incorporates document metadata directly, so topic prevalence and content can covary with party, time, or treatment within a single coherent model.
- Returns covariate effects with uncertainty via effect estimation, supporting inferential rather than merely descriptive claims about themes.
- Allows topics to correlate through the logistic-normal prior, which may be a more realistic assumption for some corpora than the uncorrelated topics of LDA; this should be checked against the data.
- Implemented in the documented R package stm, which provides tools for choosing K, labeling topics, and plotting covariate effects.
Applications
- Analyzing open-ended survey responses to see how themes differ by respondent attributes or experimental treatment.
- Tracking how the topical emphasis of legislative speeches or party communications shifts over time and across parties.
- Studying media and news coverage to measure how framing varies by outlet, region, or period.
- Examining social-media or petition text to relate topic prevalence to author characteristics.
- Validating and complementing dictionary or supervised approaches by surfacing the latent thematic structure of a corpus.
How it works
How it works
The corpus is converted into a document-term matrix after the text is tokenized and normalized, typically with stopwords and very rare terms removed and sometimes with stemming. The metadata table must be aligned row-for-row with the documents. These choices materially affect the recovered topics, so they should be documented and varied in robustness checks; the stm package exposes them through its textProcessor and prepDocuments functions.
Each document's vector of topic proportions is drawn from a logistic-normal distribution whose mean is a linear function of the document's prevalence covariates X_d, with coefficients gamma, and whose covariance Sigma allows topics to correlate. This is the core difference from LDA, which uses a fixed Dirichlet prior shared by all documents. Because the expected topic mix shifts with metadata, prevalence can rise or fall systematically with party, date, or experimental arm.
Formula
\theta_d \sim \text{LogisticNormal}(X_d\gamma,\ \Sigma)When content covariates are specified, the word distribution for a topic in a document is built from a baseline log-frequency for each word, plus deviations for the topic, for the document's covariate level y_d, and for their interaction. This lets the same topic be expressed with different vocabulary across groups, for example two parties discussing immigration with distinct word choices, instead of forcing one shared word distribution per topic.
Formula
\beta_{d,k,v} \propto \exp\!\big(m_v + \kappa^{(t)}_{k,v} + \kappa^{(c)}_{y_d,v} + \kappa^{(i)}_{k,y_d,v}\big)The posterior is intractable, so STM is fit by approximate variational expectation-maximization. A tractable family approximates the posterior over topic proportions and word assignments, and the algorithm alternately updates this variational distribution and the global parameters (gamma, Sigma, and the content coefficients) to increase the evidence lower bound. The solution depends on initialization and on the chosen number of topics K.
Formula
\max\ \mathbb{E}_q[\log p(w,\theta,z\mid X,Y)] + \mathbb{H}(q)After fitting, the relationship between covariates and topic prevalence is summarized by regressing estimated topic proportions on the covariates. Model uncertainty is propagated by repeating this over draws of the topic proportions. Each coefficient is a difference in the expected share of a document devoted to the topic, associated with a change in the covariate. It is not a probability, and it does not describe how the topic's vocabulary changes; that question belongs to content covariates. The estimates are conditional on the fitted model, so they depend on the chosen number of topics, on how each topic is interpreted and labeled, and on preprocessing. A causal reading is justified only when the covariate was randomly assigned, as in an experiment; for observational covariates, the estimates describe association. The result is a set of interpretable, uncertainty-bearing statements, such as how a topic's expected prevalence changes over time or differs by party, which are the quantities most political analyses report.
Formula
\hat{\theta}_{dk} = f(X_d) + \varepsilon_{dk}Common pitfalls
- Choosing K mechanically from a single diagnostic (e.g., held-out likelihood) without reading topics for semantic coherence and exclusivity.
- Interpreting topic-covariate effects causally when the covariate is observational rather than randomized.
- Misaligning the metadata table with the documents after dropping empty or short documents in prepDocuments, silently corrupting every covariate effect.
- Treating the labels STM suggests (or the analyst's quick labels) as validated meanings without inspecting top words and representative documents.
Frequently asked questions
How is STM different from plain LDA?
LDA assumes every document draws its topic proportions from a single shared Dirichlet prior and treats topics as independent, ignoring metadata. STM replaces that fixed prior with a logistic-normal distribution whose mean depends on document-level covariates, lets topics correlate, and can also make a topic's vocabulary depend on covariates. Where LDA leaves you to compare topics across groups by hand afterward, STM estimates the topics and covariate relationships jointly and reports the relationships with uncertainty. If the prevalence model includes only an intercept, the model has no covariate effects and is closest to a correlated topic model; see lda-topic-model and topic-modeling for the unconditioned versions.
What is the difference between prevalence and content covariates?
Prevalence covariates affect how much each document is about each topic. They shift the expected topic proportions, answering questions like 'do Republicans talk about this topic more than Democrats?' Content covariates affect the words used to express a topic. They let the same topic be discussed with different vocabulary across groups, answering 'do the two parties use different language when discussing the same topic?' You can specify either, both, or neither; content covariates are more demanding to estimate and are used more sparingly.
How do I choose the number of topics K?
There is no single correct K. The stm package provides searchK to compare candidate values on diagnostics such as held-out likelihood, semantic coherence, and exclusivity, but these are aids, not arbiters. Best practice is to combine the diagnostics with substantive reading of the top words and representative documents at several K values, choosing a model whose topics are coherent, distinct, and useful for the research question. K is a modeling choice to be justified and checked, not a parameter the data fix on their own.
Related methods
Sources
Roberts, M. E., Stewart, B. M., Tingley, D., Lucas, C., Leder-Luis, J., Gadarian, S. K., Albertson, B., & Rand, D. G. (2014). Structural Topic Models for Open-Ended Survey Responses. American Journal of Political Science, 58(4), 1064–1082.
Open DOI referenceRoberts, M. E., Stewart, B. M., & Tingley, D. (2019). stm: An R Package for Structural Topic Models. Journal of Statistical Software, 91(2), 1–40.
Open DOI referenceGrimmer, J., & Stewart, B. M. (2013). Text as Data: The Promise and Pitfalls of Automatic Content Analysis Methods for Political Texts. Political Analysis, 21(3), 267–297.
Open DOI reference