R 中的 prepDocuments 函数给出无效时间错误

问题描述 投票:0回答:0

所以我创建了一个结构主题模型(https://rdrr.io/cran/stm/),一个包含元数据的文本分类概率模型。 现在我想运行一个排列测试(https://rdrr.io/cran/stm/man/plot.STMpermute.html),为此我使用了建议的示例:

`temp<-textProcessor(documents=gadarian$open.ended.response,metadata=gadarian)
out <- prepDocuments(temp$documents, temp$vocab, temp$meta)
documents <- out$documents
vocab <- out$vocab
meta <- out$meta
set.seed(02138)
mod.out <- stm(documents, vocab, 3, prevalence=~treatment + s(pid_rep), data=meta)
summary(mod.out)
prep <- estimateEffect(1:3 ~ treatment + s(pid_rep), mod.out, meta)
plot(prep, "treatment", model=mod.out,
     method="difference",cov.value1=1,cov.value2=0)
test <- permutationTest(formula=~ treatment + s(pid_rep), stmobj=mod.out, 
                        treatment="treatment", nruns=25, documents=documents,
                        vocab=vocab,data=meta, stmverbose=FALSE)
plot(test,2, xlab="Effect", ylab="Model Index", main="Topic 2 Placebo Test")`

我将其应用于我自己的数据框的元素——如果我确实定位了错误的元素,请在这里纠正我,也许——我猜元数据参数是错误的?)

`temp <-textProcessor(documents=daten_dfm_fit_CryptoCombined$documents,metadata=daten_dfm_fit_CryptoCombined$meta)
out <- prepDocuments(temp$documents, temp$vocab, temp$meta)
documents <- out$documents
vocab <- out$vocab
meta <- out$meta
mod.out <- stm(documents, vocab, 3, prevalence=~treatment + s(pid_rep), data=meta)
summary(mod.out)
prep <- estimateEffect(1:3 ~ treatment + s(pid_rep), mod.out, meta)
plot(prep, "treatment", model=mod.outTest,
     method="difference",cov.value1=1,cov.value2=0)
permTestObj <- permutationTest(formula=~ treatment + s(pid_rep), stmobj=mod.out, 
                               treatment="treatment", nruns=100, documents=documents,
                               vocab=vocab,data=meta, stmverbose=FALSE)
plot(permTestObj,2, xlab="Effect", ylab="Model Index", main="Topic 2 Placebo Test")`

在第一行之后,当它试图创建对象“out”时,我收到了这条错误消息

`> out <- prepDocuments(temp$documents, temp$vocab, temp$meta):
Error in rep(1:length(documents), times = VsubD) : 
  invalid 'times' argument`

现在我很困惑,因为: a) 我以为我正在使用 prepDoc,这不是一个 repfunction?我的意思是我没有说明任何次数的代表? 所以我不知道怎么办 (https://www.statology.org/r-error-rep-invalid-times-argument/)应该有帮助。

b) 我定位的 dfms 的任何属性可能是错误的吗?也许如果它们包含空行?

c) 是不是因为我把错误的组件放在一起?

如果我必须提供完整代码,请告诉我 谢谢你的时间。

我尝试运行它并期望它可以不间断地工作 我研究了这个问题并尝试通过 textProcessor 或 prepDocuments 变量清理 dfms,但它们似乎都没有提供删除空条目功能

r topic-modeling
© www.soinside.com 2019 - 2024. All rights reserved.