Skip to contents

Mean proportion of each topic within groups of documents, e.g. by decade, journal or document type: a descriptive counterpart of the regressions of topic_effects(), with no model assumption and nothing smoothed.

Usage

topic_prevalence_by(theta, meta, by, weights = NULL, ...)

Arguments

theta

Document-topic matrix (model$theta, documents in rows), or a fitted model.

meta

Metadata in the order of the rows of theta.

by

Character vector of columns of meta defining the groups.

weights

Optional numeric vector, one weight per document (e.g. its number of tokens), to weight documents in the average.

...

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

Value

A long data.table with the by columns, topic, prevalence (weighted mean proportion; the topics of a group sum to 1) and n_documents.

Examples

theta <- matrix(c(0.9, 0.1, 0.2, 0.8, 0.6, 0.4), ncol = 2, byrow = TRUE)
meta <- data.frame(period = c("a", "a", "b"))
topic_prevalence_by(theta, meta, by = "period")
#>    period topic prevalence n_documents
#>    <char> <int>      <num>       <int>
#> 1:      a     1       0.55           2
#> 2:      a     2       0.45           2
#> 3:      b     1       0.60           1
#> 4:      b     2       0.40           1