R/run_topic_model.R

Defines functions run_topic_model

Documented in run_topic_model

# function to run a topic model with specified parameters
run_topic_model <- function(
	dtm,
	type = "lda",
	n_topics = 5,
	iterations = 2000
){
	LDA_control <- list(
    iter = iterations,
    burnin = iterations * 0.1
  )
	switch(type,
		"ctm" = {
      topicmodels::CTM(
        dtm,
        k = n_topics
      )
    },
		"lda" = {
      topicmodels::LDA(
        dtm,
        k = n_topics,
        method = "Gibbs",
        control = LDA_control
      )
    }
  )
}

Try the revtools package in your browser

Any scripts or data that you put into this service are public.

revtools documentation built on Jan. 8, 2020, 5:10 p.m.