title: Predicting topics for each document in the data using structural topic modeling (STM)
body: <p>I've been trying to run structural topic modeling (STM package in R) to predict topics for documents. I followed all the steps mentioned in <a href="https://cran.r-project.org/web/packages/stm/vignettes/stmVignette.pdf" rel="nofollow noreferrer">https://cran.r-project.org/web/packages/stm/vignettes/stmVignette.pdf</a>, but I can't find any object that contains documents-topics so I can export to csv.</p>
  <p>Is there a way that I can export a document-topic dataframe to a csv file from stm results? I am looking for that dataframe.</p>
  <p>Thanks</p>
  <pre><code>
      # ESTIMATION
      poliblogPrevfit = stm(documents = out$documents, vocab = out$vocab, K=30, prevalence = ~event+Covid,
                            max.em.its = 75, data=out$meta, init.type = &quot;Spectral&quot;)
      
      storage = searchK(docs, vocab, K=c(5,6,7,8,9), prevalence = ~s(eventdiff), data = meta)
      plot(storage)
      
      
      # EVALUATION: model selection and search
      ## stm model: topic number = 15 (based on searchK result)
      poliblogPrevfit = stm(documents = out$documents, vocab = out$vocab, K=15, prevalence = ~event,
                            max.em.its = 75, data=out$meta, init.type = &quot;Spectral&quot;)
      
   
      poliblogSelect = selectModel(out$documents, out$vocab, K=15, prevalence =~event, max.em.its = 75,
                                   data=out$meta, runs=20, seed=111)
      
      plotModels(poliblogSelect, pch = c(1,2,3,4), legend.position=&quot;bottomright&quot;)
      
      selectModel = poliblogSelect$runout[[1]]
      
      labelTopics(poliblogPrevfit, c(1:7)) 
      sageLabels(poliblogPrevfit,10)
      
      shortdoc &lt;- substr(out$meta$documents, 1, 200)
      thought &lt;- findThoughts(poliblogPrevfit, texts=out$data$text, topics=1, n=10)
  
  </code></pre>