prevalence, in the prior for topical content or both. See an overview of functions in the package here: stm-packagestm(documents, vocab, K,
prevalence, content, data=NULL,
init.type=c("LDA", "Random", "Spectral"), seed=NULL,
max.em.its=500, emtol=1e-5,
verbose=TRUE, reportevery=5,
LDAbeta=TRUE, interactions=TRUE,
ngroups=1, model=NULL,
gamma.prior=c("Pooled", "L1"), sigma.prior=0,
kappa.prior=c("L1", "Jeffreys"), control=list())prepDocuments forseed.stm saves the seed it uses on every run so that any result can be exactly reproduced. When attempting to reproduce a result with that seed, it should be specified here.TRUE when there are no content covariates. When set to FALSE the model performs SAGE style topic updates (sparse deviations from a baseline).TRUE. This automatically includes interactions between content covariates and the latent topics. Setting it to FALSE reduces to a model with no interactive effects.stm object to this argument you can restart an existing model. See details for more info.Pooled options uses Normal prior distributions with a topic-level pooled variance which is given a broad gamma hyperprior. The alternative L1 usesL1 prior. The second option is Jeffreys which is markedly less computationally efficient but is included for backwards compatability. Ss. The response portion of the formula should be left blank. See the examples.
The topical convent covariates are those which affect the way in which a topic is discussed. As currently implemented this must be a single variable which defines a discrete partition of the dataset (each document is in one and only one group). We may relax this in the future. While including more covariates in topical prevalence will rarely affect the speed of the model, including additional levels of the content covariates can make the model much slower to converge. This is due to the model operating in the much higher dimensional space of words in dictionary (which tend to be in the thousands) as opposed to topics.
In addition to the default priors for prevalence, we also make use of the glmnet package to allow for penalties between the L1 and L2 norm. In these settings we estimate a regularization path and then select the optimal shrinkage parameter using a user-tuneable information criterion. By default selecting the L1 option will apply the L1 penalty selecting the optimal shrinkage parameter using AIC. The defaults have been specifically tuned for the STM but almost all the relevant arguments can be changed through the control structure below. Changing the gamma.enet parameters allow the user to choose a mix between the L1 and L2 norms. When set to 1 (as by default) this is the lasso penalty, when set to 0 its the ridge penalty. Any value in between is a mixture called the elastic net.
The default prior choice for content covariates is now the L1 option. This uses an approximation framework developed in Taddy (2013) called Distributed Multinomial Regression which utilizes a factorized poisson approximation to the multinomial. See Roberts, Stewart and Airoldi (2014) for details on the implementation here. This is dramatically faster than previous versions. The old default setting which uses a Jeffreys prior is also available.
The argument init.type allows the user to specify an intialization method. The default uses collapsed gibbs sampling for the LDA model. The choice "Spectral" provides a deterministic inialization using the spectral algorithm given in Arora et al 2013. See Roberts, Stewart and Tingley (2014) for details and a comparison of differnet approaches. Particularly when the number of documents is relatively large we highly recommend the Spectral algorithm which often performs extremely well. Note that the random seed plays no role in the spectral initialization as it is completely deterministic.
Specifying an integer greater than 1 for the argument ngroups causes the corpus to be broken into the specified number of groups. Global updates are then computed after each group in turn. This approach, called memoized variational inference in Hughes and Sudderth (2013), can lead to more rapid convergence when the number of documents is large. Note that the memory requirements scale linearly with the number of groups so this provides a tradeoff between memory efficiency and computational power.
Models can now be restarted by passing an STM object to the argument model. This is particularly useful if you run a model to the maximum iterations and it terminates without converging. Note that all the standard arguments still need to be passed to the object (including any formulas, the number of topics, etc.). Be sure to change the max.em.its argument or it will simply complete one additional iteration and stop.
The control argument is a list with named components which can be used to specify numerous additional computational details. Valid components include:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]prepDocuments
labelTopics
estimateEffect#An example using the Gadarian data. From Raw text to fitted model.
temp<-textProcessor(documents=gadarian$open.ended.response,metadata=gadarian)
meta<-temp$meta
vocab<-temp$vocab
docs<-temp$documents
out <- prepDocuments(docs, vocab, meta)
docs<-out$documents
vocab<-out$vocab
meta <-out$meta
set.seed(02138)
mod.out <- stm(docs, vocab, 3, prevalence=~treatment + s(pid_rep), data=meta)
#An example of restarting a model
mod.out <- stm(docs, vocab, 3, prevalence=~treatment + s(pid_rep),
data=meta, max.em.its=5)
mod.out2 <- stm(docs, vocab, 3, prevalence=~treatment + s(pid_rep),
data=meta, model=mod.out, max.em.its=10)Run the code above in your browser using DataLab