gpt4 book ai didi

r - makeTopMatrix 中的结构主题建模 (stm) 错误(普遍性、数据): Error creating model matrix

转载 作者:行者123 更新时间:2023-12-05 03:02:17 33 4
gpt4 key购买 nike

我正在尝试运行这个 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 中运行它吗..我什至在任何地方都找不到类似的错误..

最佳答案

您的问题似乎是,通过您所做的采样,您最终得到了一个只有一个级别的因子对象:

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

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

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)

关于r - makeTopMatrix 中的结构主题建模 (stm) 错误(普遍性、数据): Error creating model matrix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54983075/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com