0

I am trying to extract topic assignments from a fit I build with R's 'lda' package. I created a fit:

fit <- lda.collapsed.gibbs.sampler(documents = documents, K = K, vocab = vocab, 
    num.iterations = G, alpha = alpha, eta = eta, initial = NULL, 
    burnin = 0, compute.log.likelihood = TRUE)

...and would like to extract a probability for each topic-document assignment or simply the most likely topic for each document. With the 'topicmodel' package I can just call

topics(fit)

to get that (as in LDA with topicmodels, how can I see which topics different documents belong to?)

How can I get the same with 'lda'?

Community
  • 1
  • 1
Sylvia
  • 315
  • 2
  • 17

1 Answers1

0

I haven't used the 'lda' package of R but I use the 'topicmodels' package in R I an create the lda fit for lets say 5 topics, using

topic.fit <- LDA(document-term matrix, 5)

now if you want to extract the probability of each topic-document assignment, use

topic.fit@gamma[1:5, ] , gamma contains the document-topic matrix

and to get the most likely topic you can use

most.likely.topic <- topics(topic.fit, 1)

hope this answers your question.

prateek
  • 23
  • 6