R中的manova错误消息:'dimnames'[1]的长度不等于数组范围

时间:2011-12-15 06:38:37

标签: arrays r anova two-way

尝试在此数据上运行manova:

创建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))

检查data.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(Degrees),再次运行acc_manova,并出现了同样的错误。

有关于此的任何想法吗?

1 个答案:

答案 0 :(得分: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