r - 集群分析,dimnames(x) <- dn 中的错误:“dimnames”[2] 的长度不等于数组范围
问题描述
我正在尝试使用 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”,因为在您的示例数据中找不到它。
推荐阅读
- java - 使用 maven 3.5 运行 jacoco 检查目标
- javascript - ExpressJS 不会触发 app.use 中的下一个路由
- java - 如何在java中将数组插入mysql数据库(列和值是数组)?
- python-3.6 - 人工智能的行为是绝对静态的吗?
- drools - OptaPlanner:如何在不构建任何解决方案的情况下计算给定实体的分数
- excel - Excel 2019:CountA 正在计算从 CSV 导入的数据中的空单元格
- javascript - 使用 JavaScirpt 解析 JSON 文件
- python - Keras:如果我多次训练 10 个 epoch,是否需要重新加载模型?
- javascript - 使用 javascript 获取表格内容
- python - Python validate arg 是特定对象的列表