Takes topics by terms matrix and returns top M terms for each topic
GetTopTerms(phi, M, return_matrix = TRUE)
A matrix whose rows index topics and columns index words
An integer for the number of terms to return
Do you want a matrix
or data.frame
/tibble
returned? Defaults to TRUE
.
If return_matrix = TRUE
(the default) then a matrix. Otherwise,
returns a data.frame
or tibble
whose columns correspond to a topic and
whose m-th row correspond to the m-th top term from the input phi
.
# Load a pre-formatted dtm and topic model
data(nih_sample_topic_model)
top_terms <- GetTopTerms(phi = nih_sample_topic_model$phi, M = 5)
str(top_terms)
#> chr [1:5, 1:30] "health" "data" "women" "studies" "swan" "ptc" "brain" ...
#> - attr(*, "dimnames")=List of 2
#> ..$ : NULL
#> ..$ : chr [1:30] "t_1" "t_2" "t_3" "t_4" ...