I am attempting to assign a list of surveyed questions into 30 different categories using the LDA function in the topicmodels package.
The code I have so far is:
source <- VectorSource(openended$q2)
corpus <- Corpus(source)
corpus <- tm_map(corpus, content_transformer(tolower))
corpus <- tm_map(corpus, removeNumbers)
corpus <- tm_map(corpus, removePunctuation)
corpus <- tm_map(corpus, stripWhitespace)
corpus <- tm_map(corpus, removeWords, stopwords('english'))
corpus <- tm_map(corpus, stemDocument, language = "english")
mat <- DocumentTermMatrix(corpus)
rowTotals <- apply(mat , 1, sum)
mat <- mat[rowTotals> 0, ]
burnin <- 4000
iter <- 2000
thin <- 500
seed <-list(2003,5,63,100001,765)
nstart <- 5
best <- TRUE
k <- 30
ldaOut <-LDA(mat,k, method="Gibbs", control=list(nstart=nstart, seed = seed,
best=best, burnin = burnin, iter = iter, thin=thin))
ldaOut.topics <- as.matrix(topics(ldaOut))
write.csv(ldaOut.topics,file=paste("LDAGibbs",k,"DocsToTopics.csv"))
I already have 10% of the data in openended$q2 appropriately coded, how can I train the algorithm using that data?
Thanks!