Learn R Programming

psychtm (version 2021.1.0)

term_score: Compute term-scores for each word-topic pair

Description

For more details, see Blei, D. M., & Lafferty, J. D. (2009). Topic models. In A. N. Srivastava & M. Sahami (Eds.), Text mining: Classification, clustering, and applications. Chapman and Hall/CRC.

Usage

term_score(beta_)

Arguments

beta_

A \(K\) x \(V\) matrix of \(V\) vocabulary probabilities for each of \(K\) topics.

Value

A \(K\) x \(V\) matrix of term-scores (comparable to tf-idf).

Examples

Run this code
# NOT RUN {
#' library(lda) # Required if using `prep_docs()`

data(teacher_rate)  # Synthetic student ratings of instructors
docs_vocab <- prep_docs(teacher_rate, "doc")
vocab_len <- length(docs_vocab$vocab)
m1 <- gibbs_sldax(rating ~ I(grade - 1), m = 2,
                  data = teacher_rate, docs = docs_vocab$documents,
                  V = vocab_len, K = 2, model = "sldax")
hbeta <- est_beta(m1)
ts_beta <- term_score(hbeta)
# One row per topic, one column per unique term in the vocabulary
str(ts_beta)

# }

Run the code above in your browser using DataLab