Description Usage Arguments Value Note Examples
View source: R/evaluation_metrics.R
Function to calculate Rsquared for a topic model. This uses a geometric interpretation of Rsquared as the proportion of total distance each document is from the center of all the documents that is explained by the model.
1  CalcTopicModelR2(dtm, phi, theta, ...)

dtm 
A documents by terms dimensional document term matrix of class

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_jdocument_d) 
... 
Other arguments to be passed to 
Returns an object of class numeric
representing the proportion of variability
in the data that is explained by the topic model.
This function performs parallel computation if dtm
has more than 3,000
rows. The default is to use all available cores according to detectCores
.
However, this can be modified by passing the cpus
argument when calling
this function.
1 2 3 4 5 6 7 8 9 10 11  # Load a preformatted dtm and topic model
data(nih_sample_dtm)
data(nih_sample_topic_model)
# Get the Rsquared of the model
r2 < CalcTopicModelR2(dtm = nih_sample_dtm,
phi = nih_sample_topic_model$phi,
theta = nih_sample_topic_model$theta)
r2

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.