2011-12-15 99 views
1

試圖對這個數據執行MANOVA:MANOVA中的R錯誤消息: 'dimnames'[1]不等於陣列程度的長度

創建data.frame:

acc <- data.frame(Degrees = c("5","8","10"), MPH10=c(0.35, 0.37, 0.32), 
MPH25=c(0.19, 0.28, 0.30), MPH40=c(0.14, 0.19, 0.29), MPH55=c(0.10, 0.19, 0.23)) 

校驗數據.frame:

acc 
    Degrees MPH10 MPH25 MPH40 MPH55 
1  5 0.35 0.19 0.14 0.10 
2  8 0.37 0.28 0.19 0.19 
3  10 0.32 0.30 0.29 0.23 

我輸入:

acc_manova <- manova(cbind(MPH10,MPH25,MPH40,MPH55) ~ Degrees, data = acc) 

然後運行它:

acc_manova 

我得到一個錯誤信息:

Call: 
    manova(cbind(MPH10, MPH25, MPH40, MPH55) ~ as.factor(Degrees), 
    data = acc) 

Terms: 
Error in dimnames(tmp) <- list(c(rn, "Deg. of Freedom"), nmeffect) : 
    length of 'dimnames' [1] not equal to array extent 

所以我想它與度列的名稱做:D05,D08,D10,所以我放棄了d和0名持有人。有相同的錯誤信息

然後我添加as.factor(度),再次運行acc_manova,並提出了相同的錯誤。

對此的任何想法?

+0

您可以使用dput轉儲數據集的可重複版本。這會讓事情變得更容易。 – 2011-12-15 10:53:53

+0

雖然我找出dput(以前從未使用過),但這裏是如何獲取data.frame acc:acc < - data.frame(Degrees = c(「5」,「8」,「10」),MPH10 = c (0.35,0.37,0.32),MPH25 = c(0.19,0.28,0.30),MPH40 = c(0.14,0.19,0.29),MPH55 = c(0.10,0.19,0.23)) – Travis 2011-12-15 12:19:32

回答

1

您的學位欄不是數字,而是一個因子(分類數據)。將因子更改爲數字可解決您的問題:

acc$Degrees = as.numeric(acc$Degrees) 
acc_manova <- manova(cbind(MPH10,MPH25,MPH40,MPH55) ~ Degrees, data = acc) 
> acc_manova 
Call: 
    manova(cbind(MPH10, MPH25, MPH40, MPH55) ~ Degrees, data = acc) 

Terms: 
        Degrees Residuals 
resp 1   1.2500e-03 1.6667e-05 
resp 2   0.000200000 0.006666667 
resp 3   0.005000000 0.006666667 
resp 4   0.000800000 0.008066667 
Deg. of Freedom   1   1 

Residual standard error: 0.004082483 0.08164966 0.08164966 0.08981462 
Estimated effects may be unbalanced