I am using this line to obtain the most probable words for specific topics (using the lda package):
ldaOut.terms <- as.matrix(terms(ldaOut,6))
write.csv(ldaOut.terms,file=paste("topic_model",k,"TopicsToTerms.csv"))
ldaOut.terms[1:6,]
However, when I try to visualize it using the LDAvis package, the topic numbers do not correspond to the ones assigned with the previous command.
For the record, I am using this line:
topicmodels2LDAvis <- function(x, ...){
post <- topicmodels::posterior(x)
if (ncol(post[["topics"]]) < 3) stop("The model must contain > 2 topics")
mat <- x@wordassignments
LDAvis::createJSON(
phi = post[["terms"]],
theta = post[["topics"]],
vocab = colnames(post[["terms"]]),
doc.length = slam::row_sums(mat, na.rm = TRUE),
term.frequency = slam::col_sums(mat, na.rm = TRUE)
)
}
serVis(topicmodels2LDAvis(ldaOut))
Can you help me please?
Thanks in advance!
PS: Its my first time trying to use R, so I am not aware of numerous concepts, i'm sorry.
I expect to obtain 17 topics for both of my analyses (which is okay so far) and the topic numbers to correspond to the ones in the map visualization.