Skip to contents

Pairwise similarity of the topics' word distributions \(\beta_k\):

  • "cosine": \(\frac{\beta_k \cdot \beta_l}{\|\beta_k\| \|\beta_l\|}\), in [0, 1]; its mean over pairs is the criterion of Cao et al. (2009), who chose K to minimise it.

  • "jsd": one minus the Jensen-Shannon distance (square root of the Jensen-Shannon divergence in base 2), in [0, 1].

High similarity between two topics means the model split one theme in two (or did not separate two themes in the other topics).

Usage

topic_similarity(model, method = c("cosine", "jsd"), ...)

Arguments

model

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

method

"cosine" or "jsd".

...

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

Value

A K x K numeric matrix (1 on the diagonal).

References

Cao, J., Xia, T., Li, J., Zhang, Y. and Tang, S. (2009). A density-based method for adaptive LDA model selection. Neurocomputing, 72(7-9), 1775-1781. doi:10.1016/j.neucom.2008.06.011

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("wage", "labour", "trade"))
topic_similarity(mdl)
#>           [,1]      [,2]
#> [1,] 1.0000000 0.5518885
#> [2,] 0.5518885 1.0000000