gpt4 book ai didi

r - 聚类分析,dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent 中的错误

转载 作者:行者123 更新时间:2023-12-04 15:36:44 25 4
gpt4 key购买 nike

我正在尝试使用 poLCA 包进行潜在聚类分析。

我的数据框可以在这里下载为 rda 文件并将其保存到您的工作目录中: https://drive.google.com/open?id=1eGJprHaXdoVhKNlGD5VcsoND7iyIoNwJ

load(file = "QuestionData.rda")

当我尝试运行 LCA 时:

library("MPsychoR")
library("poLCA")
formula <- cbind(Question1, Question2, Question3, Question4) ~ 1
OneClass <- poLCA(formula, data = Output, nclass = 1, nrep = 3)
TwoClass <- poLCA(formula, data = Output, nclass = 2, nrep = 3)

我收到以下错误:

Error in dimnames(x) <- dn : 
length of 'dimnames' [2] not equal to array extent

通过阅读和查看遇到此错误的其他人,似乎是因为他们的数据框中的列数与他们输入函数的列名数之间存在差异......但是我的数据框中有 4 列,并且有 4 列添加到 poLCA 函数中。谁能帮助我理解为什么我会遇到此错误?

如果你不想下载我的数据,我的数据框的一般结构如下:

Question1 <- c('Sufficient', 'Problematic', 'Problematic', 'Sufficient', 
'Excellent')
Question2 <- c('Insufficient', 'Insufficient', 'Insufficient', 'Sufficient',
'Sufficient')
Question3 <- c('Sufficient', 'Sufficient', 'Insufficient', 'Sufficient',
'Sufficient')
Question4 <- c('Problematic', 'Insufficient', 'Problematic', 'Problematic',
'Excellent')
Question5 <- c('Insufficient', 'Sufficient', 'Sufficient', 'Exceptional',
'Exceptional')

DF <- data.frame(Participants, Question1, Question2, Question3, Question4,
Question5)

DF$Question1 <- factor(DF$Question1, levels = c("Problematic",
"Insufficient", "Sufficient", "Excellent"), ordered=TRUE)
DF$Question2 <- factor(DF$Question2, levels = c("Problematic",
"Insufficient", "Sufficient", "Excellent"), ordered=TRUE)
DF$Question3 <- factor(DF$Question3, levels = c("Problematic",
"Insufficient", "Sufficient", "Excellent"), ordered=TRUE)
DF$Question4 <- factor(DF$Question4, levels = c("Problematic",
"Insufficient", "Sufficient", "Excellent"), ordered=TRUE)
DF$Question5 <- factor(DF$Question5, levels = c("Problematic",
"Insufficient", "Sufficient", "Excellent", "Exceptional"), ordered=TRUE)

最佳答案

每个响应变量都有不同的级别:

summary(Output)
Question1 Question2 Question3 Question4
Problematic :150 Problematic : 57 Problematic :181 Problematic :456
Insufficient:211 Insufficient:157 Insufficient:320 Insufficient :130
Sufficient :238 Sufficient :692 Sufficient :405 Sufficient : 48
Excellent :307 Excellent : 0 Excellent :272
ExcellentPlus: 0

如果我没看错(对你的数据不太熟悉),你可以让它们具有相同的级别:

NewOutput = Output
for(i in 1:ncol(NewOutput)){
NewOutput[,i] = factor(as.character(Output[,i]),order=TRUE,
levels=c("Problematic","Insufficient","Sufficient","Excellent"))
}
poLCA(cbind(Question1,Question2,Question3,Question4)~1,data=NewOutput,nclass=1)

我从你的因素中省略了“ExcellentPlus”,因为它在你的示例数据中找不到。

关于r - 聚类分析,dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59506814/

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