Skip to contents

Pearson correlation between the proportions of topics over documents (the "simple" method of stm::topicCorr()). Two topics that tend to appear in the same documents correlate positively. Since the proportions of a document sum to 1, most correlations are slightly negative: read the positive ones, and the strongest negative ones.

Usage

topic_correlation(model, min_cor = NULL, ...)

Arguments

model

A fitted stm model, or its document-topic matrix theta.

min_cor

Optional numeric scalar: keep pairs whose correlation is at least this value (e.g. 0.1).

...

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

Value

A data.table with one row per pair of topics (topic_a < topic_b) and correlation, by decreasing correlation.

Examples

theta <- matrix(
  c(0.7, 0.2, 0.1, 0.1, 0.3, 0.6, 0.4, 0.4, 0.2, 0.2, 0.1, 0.7),
  ncol = 3, byrow = TRUE
)
topic_correlation(list(theta = theta))
#>    topic_a topic_b   correlation
#>      <int>   <int>         <num>
#> 1:       1       2  1.083368e-16
#> 2:       2       3 -4.385290e-01
#> 3:       1       3 -8.987170e-01