This function takes an object of class lda_topic_model and draws samples from the posterior of either phi or theta. This is useful for quantifying uncertainty around parametrs of the final model.

# S3 method for lda_topic_model
posterior(object, which = "theta",
  num_samples = 100, ...)

Arguments

object

An object of class lda_topic_model

which

A character of either 'theta' or 'phi', indicating from which matrix to draw posterior samples

num_samples

Integer number of samples to draw

...

Other arguments to be passed to TmParallelApply.

Value

Returns a data frame where each row is a single sample from the posterior. Each column is the distribution over a single parameter. The variable var is a facet for subsetting by document (for theta) or topic (for phi).

References

Heinrich, G. (2005) Parameter estimation for text analysis. Technical report. http://www.arbylon.net/publications/text-est.pdf

Examples

# NOT RUN {
a <- posterior(object = nih_sample_topic_model, which = "theta", num_samples = 20)

plot(density(a$t1[a$var == "8693991"]))

b <- posterior(object = nih_sample_topic_model, which = "phi", num_samples = 20)

plot(denisty(b$research[b$var == "t_5"]))
# }