makeTopMatrix(患病率,数据)中的结构主题建模(stm)错误:创建模型矩阵时出错

时间:2019-03-04 12:15:44

标签: r topic-modeling

我正在尝试运行此stm教程的初始步骤

https://github.com/dondealban/learning-stm

使用此数据集,它是原始数据集的一部分

http://www.mediafire.com/file/1jk2aoz4ac84jn6/data.csv/file

install.packages("stm")
library(stm)
load("VignetteObjects.RData") 
data <- read.csv("C:/data.csv") 
head(data)
processed <- textProcessor(data$documents, metadata=data)
out <- prepDocuments(processed$documents, processed$vocab, processed$meta)
docs <- out$documents
vocab <- out$vocab
meta <- out$meta


poliblogPrevFit <- stm(out$documents, out$vocab, K=4, prevalence=~rating+s(day), 
                       max.em.its=200, data=out$meta, init.type="Spectral", 
                       seed=8458159)

但是我仍然收到相同的错误

Error in makeTopMatrix(prevalence, data) : Error creating model matrix.
                 This could be caused by many things including
                 explicit calls to a namespace within the formula.
                 Try a simpler formula.

任何人都可以在64位MS Windows R-3.5.2。中运行它。我什至在任何地方都找不到类似的错误。

1 个答案:

答案 0 :(得分:1)

似乎您的问题是,在进行采样时,您最终得到的因子对象只有一个级别:

data <- read.csv("https://raw.githubusercontent.com/dondealban/learning-stm/master/data/poliblogs2008.csv")

processed <- textProcessor(data$documents, metadata = data)
out <- prepDocuments(processed$documents, processed$vocab, processed$meta)
docs <- out$documents
vocab <- out$vocab
meta <- out$meta

levels(meta$rating)
[1] "Conservative" "Liberal" 

poliblogPrevFit <- stm(docs, vocab, K = 4, prevalence = ~rating+s(day), 
                       max.em.its = 200, data = out$meta, init.type = "Spectral", 
                       seed = 8458159)

使用这样的变量没有任何意义,因为情况之间没有差异。如果您使用原始数据,则您的代码绝对可以正常工作:

akka.pattern.AskableActorRef