R 中的马诺瓦错误消息:“dimnames”的长度; [1] 不等于数组范围

发布于 2024-12-21 19:09:15 字数 990 浏览 5 评论 0原文

尝试对此数据运行马诺瓦:

创建一个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,并出现了相同的错误。

对此有什么想法吗?

Trying to run manova on this data:

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

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

I type in:

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

then run it:

 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

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

then I added as.factor(Degrees), ran acc_manova again, and came up with the same error.

Any ideas on this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍风燃霜 2024-12-28 19:09:15

您的 Degrees 列不是数字,而是一个因素(分类数据)。将因子更改为数字可以解决您的问题:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文