【发布时间】:2020-06-28 22:20:13
【问题描述】:
联合函数的输出有问题。 我有 5 个属性,每个属性有 3 个级别,但是在输出中,从第三级的第二个属性开始,结果是 NA,我不知道我能做些什么来解决这个问题。 这是我的代码和联合函数的结果(img.输出联合函数)。
你能帮帮我吗?
alimentatie<-c("mancare gatita","fast food","amandoua in mod alternativ")
activitati<-c("regulat","de cateva ori pe luna","foarte rar")
bauturi<-c("evit cat de mult pot","oricat de des simt nevoia","ocazional")
odihna<-c("7-8 ore","4-6 ore","mai mult de 8 ore")
Recreere<-c("3-6","mai mult de 6","mai putin de 3")
factor_levels<-as.data.frame(c(alimentatie,activitati,bauturi,odihna,recreere))
colnames(factor_levels)<-"levels"
data<-expand.grid(alimentatie,activitati,bauturi,odihna,recreere)
colnames(data)<-c("Alimentatie","Activitati","Bauturi","Odihna","Recreere")
facdesign_full<-caFactorialDesign(data = data, type = "full")
encdesign_full<-caFactorialDesign(facdesign_full)
response<-read.table("cc.txt", sep="\t",header = T)
response<-as.data.frame(response)
conjoint_analysis<-Conjoint(response,encdesign_full,factor_levels)
我将5个问题的每个答案(一共59个答案)编码为“0 1和2”的值为:
Alimentatie: "mancare gatita" code 0, "fast food" code 1 ,"amandoua in mod alternativ" code 2;
Activitati: "regulat" code 0,"de cateva ori pe luna" code 1,"foarte rar" code 2;
Bauturi: "evit cat de mult pot" code 0,"oricat de des simt nevoia" code 1 ,"ocazional" code 2;
Odihna: "7-8 ore" code 0,"4-6 ore" code 1,"mai mult de 8 ore" code 2;
Recreere: "3-6" code 0,"mai mult de 6" code 1,"mai putin de 3" code 2
我附上了一张照片(数据),其中包含 cc.csv 文件的一部分(因为 txt 文件出现偏移)。
数据: Data Link
dput(rasps)
structure(list(`Profil 1` = c(0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L,
0L, 0L, 2L, 0L, 2L, 0L, 1L, 2L, 0L, 2L, 0L, 2L, 0L, 0L, 2L, 0L,
2L, 0L, 0L, 0L, 2L, 2L, 2L, 0L, 0L, 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 0L, 1L, 0L, 0L, 2L, 2L, 2L, 2L, 0L, 2L, 0L, 0L, 0L, 2L, 2L
)), class = "data.frame", row.names = c(NA, 59L))
更新代码后:
输出联合函数:
【问题讨论】:
-
嗨,欢迎来到 SO!目前很难解决您的问题,因为我们无权访问您的
cc.txt文件。如果您可以在问题正文中添加该文件或一些模拟数据,事情会变得容易得多。请查看此帮助中心(页面)[stackoverflow.com/help/minimal-reproducible-example],以更好地了解我的建议。 -
另外,根据您的代码的呈现方式,我在
factor_levels行出现错误,因为Recreere对象使用大写的R,而因子级别行使用recreere较低案子。请编辑您的问题以更正此错字。 -
我更正了代码,我用小写的那个对象写了。此外,我添加了一部分数据,这些数据代表了调查答案的编纂。我希望现在更好。谢谢!
标签: r data-mining data-analysis