knitr::opts_chunk$set(eval = T, echo = TRUE)

Preparing documents and keywords

Please read Preparation for the reading of documents and creating a list of keywords. We use bills data we prapared (documents and keywords).

library(keyATM)
data(keyATM_data_bills)

bills_keywords <- list(
                       Education = c("education", "child", "student"),
                       Law       = c("court", "law", "attorney"),
                       Health    = c("public", "health", "program"),
                       Drug      = c("drug", "treatment")
                      )

library(quanteda)
bills_dfm <- keyATM_data_bills$doc_dfm  # quanteda object
keyATM_docs <- keyATM_read(bills_dfm)

Fitting the model

out <- keyATM(docs              = keyATM_docs,    # text input
              no_keyword_topics = 3,              # number of topics without keywords
              keywords          = bills_keywords, # keywords
              model             = "base",         # select the model
              options           = list(seed = 50)
             )

The default number of iterations is 1500. Please check this page for available options.

Saving the model

Once you fit the model, you can save the model with save() for replication.

save(out, file="SAVENAME.rds")

To load the model, you can use readRDS() function.

out <- readRDS(file="SAVENAME.rds")

Checking top words

top_words(out)


Shusei-E/keyATM documentation built on Dec. 23, 2019, 6:34 p.m.