How to make a function using STM package?

Viewed 25

I have a list of different corpuses I want to create structural topic models for.

When I apply the STM function to the list, I get this error:

"Error in round(x) : non-numeric argument to mathematical function"

stmfunction <- function(y) {
  
   uncorpus.dfm.trim <- dfm_trim(y, min_docfreq = 0.075, max_docfreq = 0.90, docfreq_type = "prop") # min 7.5% / max 95%

   dfm2stm <- convert(uncorpus.dfm.trim, to = "stm")

   model.stm <- stm(dfm2stm$documents, dfm2stm$vocab, K = topic.count, data = dfm2stm$meta, init.type = "Spectral")

   return(model.stm)
}

all_stm <- lapply(dfmlist, stmfunction)

It's this part of the script that makes the above return the error

model.stm <- stm(dfm2stm$documents, dfm2stm$vocab, K = topic.count, data = dfm2stm$meta, init.type = "Spectral")

Any ideas on how to fix this?

TIA

0 Answers
Related