Learn R Programming

textmineR (version 3.0.4)

CalcTopicModelR2: Calculate the R-squared of a topic model.

Description

Function to calculate R-squared for a topic model. This uses a geometric interpretation of R-squared as the proportion of total distance each document is from the center of all the documents that is explained by the model.

Usage

CalcTopicModelR2(dtm, phi, theta, ...)

Arguments

dtm

A documents by terms dimensional document term matrix of class dgCMatrix or of class matrix.

phi

A topics by terms dimensional matrix where each entry is p(term_i |topic_j)

theta

A documents by topics dimensional matrix where each entry is p(topic_j|document_d)

...

Other arguments to be passed to TmParallelApply. See note, below.

Value

Returns an object of class numeric representing the proportion of variability in the data that is explained by the topic model.

Examples

Run this code
# NOT RUN {
# Load a pre-formatted dtm and topic model
data(nih_sample_dtm) 
data(nih_sample_topic_model)

# Get the R-squared of the model
r2 <- CalcTopicModelR2(dtm = nih_sample_dtm, 
                     phi = nih_sample_topic_model$phi, 
                     theta = nih_sample_topic_model$theta)


r2
# }

Run the code above in your browser using DataLab