mergeTopics: Merge topics into fewer themes

View source: R/merging.R

mergeTopicsR Documentation

Merge topics into fewer themes

Description

This operation is especially useful for the analysis of the model's output, by grouping together topics that share a common theme.

Usage

mergeTopics(x, merging_list)

Arguments

x

a LDA() or rJST() model.

merging_list

a list where each element is an integer vector containing the indices of topics to be merged. If named, the list's names become the label of the aggregated themes.

Details

Topics are aggregated at the word assignment level. New document-topic and topic-word probabilities are derived from the aggregated assignments.

Note that the output of this function does not constitute an estimated topic model, but merely an aggregation to ease the analysis. It is not advised to use grow() on the merged topic model as it will radically affect the content and proportions of the new themes.

Value

A LDA() or rJST() model with the merged topics.

See Also

sentopics_labels

Examples

lda <- LDA(ECB_press_conferences_tokens, K = 5)
lda <- grow(lda, 100)
merging_list <- list(
  c(1,5),
  2:4
)
mergeTopics(lda, merging_list)

# also possible with a named list
merging_list2 <- list(
  mytheme_1 = c(1,5),
  mytheme_2 = 2:4
)
merged <- mergeTopics(lda, merging_list2)
sentopics_labels(merged)

# implemented for rJST
rjst <- rJST(ECB_press_conferences_tokens, lexicon = LoughranMcDonald)
rjst <- grow(rjst, 100)
mergeTopics(rjst, merging_list2)

sentopics documentation built on May 31, 2023, 8:26 p.m.