wordcounts_stm_inputs | R Documentation |
This is a helper function for transforming word-counts-type data into the
form expected by stm
from the stm package. Given a
data frame from read_wordcounts
(and optionally a frame of
metadata), it yields a list whose components can be passed as arguments to
stm
. See below for example usage.
wordcounts_stm_inputs(counts, meta = NULL)
counts |
data frame as returned from |
meta |
optional metadata data frame (with an |
Some memory-management might be a good idea here. Once you have the list of
inputs from this function, you no longer need the counts
object.
a list with elements documents
, vocab
, data
(if
meta
has been supplied). These elements are suitable to be passed as
the parameters of those names to stm
.
foreign_model
for using this package's
model-exploration utilities in conjunction with an STM.
## Not run: library(stm) counts <- read_wordcounts(Sys.glob("wordcounts/*.CSV")) meta <- read_dfr_metadata("citations.tsv") corpus <- wordcounts_stm_inputs(counts, meta) m <- stm(documents=corpus$documents, vocab=corpus$vocab, data=corpus$data, K=25, prevalence= ~ journaltitle) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.