我是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個概率箱。您還需要根據錯誤指示設置變量的類型。 ...對於初學者 – John
感謝您的建議。根據這個[link](http://stackoverflow.com/questions/8320603/how-to-do-one-way-anova-in-r-with-unequal-sample-sizes),我認爲不相等的樣本量是這個分析很好。此外,對於類型,我試圖確保因變量列是數字與as.numeric(我嘗試了各種其他的東西),但似乎沒有任何工作。這些類型應該是什麼? –