Learn R Programming

textmineR (version 3.0.4)

CalcLikelihood: Calculate the log likelihood of a document term matrix given a topic model

Description

This function takes a DTM, phi matrix (P(word|topic)), and a theta matrix (P(topic|document)) and returns a single value for the likelihood of the data given the model.

Usage

CalcLikelihood(dtm, phi, theta, ...)

Arguments

dtm

The document term matrix of class dgCMatrix.

phi

The phi matrix whose rows index topics and columns index words. The i, j entries are P(word_i | topic_j)

theta

The theta matrix whose rows index documents and columns index topics. The i, j entries are P(topic_i | document_j)

...

Other arguments to pass to TmParallelApply. See note, below.

Value

Returns an object of class numeric corresponding to the log likelihood.

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 likelihood of the data given the fitted model parameters
ll <- CalcLikelihood(dtm = nih_sample_dtm, 
                     phi = nih_sample_topic_model$phi, 
                     theta = nih_sample_topic_model$theta)

ll
# }

Run the code above in your browser using DataLab