2013-07-16 112 views
1

我是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

在重複測量方差分析中,每個對象必須在每種情況下只出現一次,因此您*不能*具有不相等的樣本大小。您需要放棄不落入每個垃圾箱的主體。或者,考慮到您的數據看起來可能如此,請添加0個概率箱。您還需要根據錯誤指示設置變量的類型。 ...對於初學者 – John

+0

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

回答

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和貝茨(斯普林格,2000)強烈推薦閱讀,如果你是 朝這個方向前進。

這可能是一個好主意,模擬/彌補一些平衡數據,並做 分析既aov()lme(),看輸出,並確保 你能看到的對應是/知道這是怎麼回事。

+0

謝謝!我將您的代碼改編爲我的數據,而且您不確定如何解釋這些結果。我會研究lme()。再次感謝。 =) –