Skip to contents

Cleans the text item via clean_text_responses(), tokenises with tidytext::unnest_tokens() (tidyeval column names via rlang::sym() and !!, not bare symbols; see the source comment at the tokenising step for why), casts to a document-term matrix, converts it to stm's corpus format with stm::readCorpus(type = "slam") and stm::prepDocuments(), and fits stm::stm() after a fixed set.seed() (stm's own fit is not otherwise seed-stable).

Usage

sframe_run_stm_topics(data, roles, options, instrument)

Arguments

data

A data.frame of responses.

roles

A list with item, the text/textarea item id.

options

A list; k (topic count, default 4L – a demonstration value, not a recommendation; see vignette("text-analysis")'s topic- modelling section for topicmodels::perplexity()-based selection), seed (default 42L), stop_words (passed through to the tokeniser).

instrument

Optional sframe instrument, passed to clean_text_responses() for item-type validation.

Value

A runner-contract result list: test = "stm_topics", table (topic/proportion/term/beta/rank; proportion is the topic's mean document weight, beta its per-term probability, both from the fitted stm object), fit (a runtime-only list holding the stm model object and the document-to-respondent mapping needed by extract_quotes()), apa, prompt. On failure: list(test = "stm_topics", error = <message>).