我正在尝试使用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)
发布于 2019-12-28 09:55:36
每个响应变量都有不同的级别:
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“,因为在示例数据中找不到它。
https://stackoverflow.com/questions/59506814
复制相似问题