0
votes

I'm performing LDA topic modeling on my dataset of tweets collected from several twitter accounts which consists of 9582 documents and 4144 terms after pre-processing. In order to run the LDA function, I have to define the parameter values that control how many Gibbs sampling draws are made when running the model.

fitted_many <- lapply(sequ, function(k) LDA(dtmTopicModeling, k = k,
method = "Gibbs",control = list(burnin = burnin, iter = iter, keep = keep) ))

How do I define the values of burnin, iter and keep for the above function?

2

2 Answers

1
votes

You don't need the anonymous function for lapply here, since all you're doing is passing the k value along to LDA. Instead, you want something like:

fitted_many <- lapply(sequ,
                      LDA,
                      x = dtmTopicModeling,
                      method = "Gibbs",
                      control = list(burnin = burnin_value,
                                     iter = iter_value,
                                     keep = keep_value))

As Oriol mentions, the ... arguments in lapply will be passed to the referenced function. By referencing LDA directly in lapply, you just have to make sure to name the x argument, since the k value is the second argument for LDA.

On the other hand, if you need different values of burnin, iter, and keep for each k value, then you would need to pass multiple varying arguments. There are several ways to do that, though I think purrr::pmap is the most direct.

0
votes

The signature of lapply is lapply(X, FUN, ...). The three dots refer to the optional arguments to FUN. So you should be able to provide those arguments separated by commas after the function.