我是R的新手,我现在已经阅读了这些论坛(寻求R的帮助),但这是我第一次发帖。在谷歌搜索每个错误后,我仍然无法弄清楚并修复我的错误。
我正在尝试运行具有不相等样本大小的单向重复测量ANOVA。这是我的数据的玩具版本和我正在使用的代码。 (如果重要的话,我的真实数据有12个箱子,每个箱子里的值最多为14到20个。)
## the data: average probability for a subject, given reaction time bin
bin1=c(0.37,0.00,0.00,0.16,0.00,0.00,0.08,0.06)
bin2=c(0.33,0.21,0.000,1.00,0.00,0.00,0.00,0.00,0.09,0.10,0.04)
bin3=c(0.07,0.41,0.07,0.00,0.10,0.00,0.30,0.25,0.08,0.15,0.32,0.18)
## creating the data frame
# dependent variable column
probability=c(bin1,bin2,bin3)
# condition column
bin=c(rep("bin1",8),rep("bin2",11),rep("bin3",12))
# subject column (in the order that will match them up with their respective
# values in the dependent variable column)
subject=c("S2","S3","S5","S7","S8","S9","S11","S12","S1","S2","S3","S4","S7",
"S9","S10","S11","S12","S13","S14","S1","S2","S3","S5","S7","S8","S9","S10",
"S11","S12","S13","S14")
# putting together the data frame
dataFrame=data.frame(cbind(probability,bin,subject))
## one-way repeated measures anova
test=aov(probability~bin+Error(subject/bin),data=dataFrame)
这些是我得到的错误:
Error in qr.qty(qr.e, resp) :
invalid to change the storage mode of a factor
In addition: Warning messages:
1: In model.response(mf, "numeric") :
using type = "numeric" with a factor response will be ignored
2: In Ops.factor(y, z$residuals) : - not meaningful for factors
3: In aov(probability ~ bin + Error(subject/bin), data = dataFrame) :
Error() model is singular
对于复杂性感到抱歉(假设它很复杂;对我而言)。谢谢你的时间。
答案 0 :(得分:3)
对于不平衡的重复测量设计,它可能是最容易的
使用lme
(来自nlme
包):
## this should be the same as the data you constructed above, just
## a slightly more compact way to do it.
datList <- list(
bin1=c(0.37,0.00,0.00,0.16,0.00,0.00,0.08,0.06),
bin2=c(0.33,0.21,0.000,1.00,0.00,0.00,0.00,0.00,0.09,0.10,0.04),
bin3=c(0.07,0.41,0.07,0.00,0.10,0.00,0.30,0.25,0.08,0.15,0.32,0.18))
subject=c("S2","S3","S5","S7","S8","S9","S11","S12",
"S1","S2","S3","S4","S7","S9","S10","S11","S12","S13","S14",
"S1","S2","S3","S5","S7","S8","S9","S10","S11","S12","S13","S14")
d <- data.frame(probability=do.call(c,datList),
bin=paste0("bin",rep(1:3,sapply(datList,length))),
subject)
library(nlme)
m1 <- lme(probability~bin,random=~1|subject/bin,data=d)
summary(m1)
唯一真正的问题是解释的某些方面等。 与经典的平方和分解方法相差甚远 (例如,对方差分量进行显着性检验相当棘手)。 Pinheiro和Bates(Springer,2000)强烈推荐阅读,如果你的话 朝着这个方向前进。
模拟/构建一些平衡数据并做到这一点可能是个好主意
使用aov()
和lme()
进行分析,查看输出,并确保
你可以看到通信的位置/知道发生了什么。