MANOVA R中错误消息:“dimnames'[1]不等于阵列程度的长度 [英] manova in R error message: length of 'dimnames' [1] not equal to array extent
本文介绍了MANOVA R中错误消息:“dimnames'[1]不等于阵列程度的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图在这个数据上运行MANOVA:
Trying to run manova on this data:
创建一个data.frame:
Create a 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:
check the 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
我得到一个错误信息:
I get an error message:
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占位符。有相同的错误消息
So I figure it has to do with the names of the degrees column: d05,d08,d10 so I dropped the d and 0 place holder. Had the same error message
然后我加入as.factor(度),又跑到acc_manova,并用同样的错误出现了。
then I added as.factor(Degrees), ran acc_manova again, and came up with the same error.
在这个任何想法?
推荐答案
您度列不是数字,而是一个因子(分类数据)。更改因子数值解决您的问题:
Your Degrees column is not numeric, but a factor (categorical data). Changing the factor to numeric solves your problem:
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
这篇关于MANOVA R中错误消息:“dimnames'[1]不等于阵列程度的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文