wordcounts_stm_inputs: Convert word counts data frame to Structural Topic Model...

wordcounts_stm_inputsR Documentation

Convert word counts data frame to Structural Topic Model inputs

Description

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.

Usage

wordcounts_stm_inputs(counts, meta = NULL)

Arguments

counts

data frame as returned from read_wordcounts

meta

optional metadata data frame (with an id column to be matched against counts$id).

Details

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.

Value

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.

See Also

foreign_model for using this package's model-exploration utilities in conjunction with an STM.

Examples

## 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)


agoldst/dfrtopics documentation built on July 15, 2022, 4:13 p.m.