在 R 中没有复制就无法计算出双因素方差分析

发布于 2024-12-21 12:58:56 字数 696 浏览 5 评论 0原文

我尝试使用 manova() ,但似乎无法获得正确的编程。我尝试了这种方式(在另一篇文章中):

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

文本问题与踏板旋转和初始速度作为加速度的预测因素有关。

这是数据:

acc <- data.frame(Degrees = c("d5","d8","d10"), 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))

ACC

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 tried using manova() and can not seem to get the correct programming in. I tried it this way (in a different post):

manova in R error message: length of 'dimnames' [1] not equal to array extent

the text question has to do with pedal rotation and initial speed being predictors of acceleration.

here is that data:

acc <- data.frame(Degrees = c("d5","d8","d10"), 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))

acc

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

no idea what to do next.

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

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

发布评论

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

评论(1

请你别敷衍 2024-12-28 12:58:56

传统的答案是:

macc <- melt(acc, id.var="Degrees")
lm(value ~ Degrees + variable, macc)
anova(lm(value ~ Degrees + variable, macc))

剩下的就是构建对结果的正确描述。 (请注意,我使用“+”而不是“*”)。使用交互模型构建饱和模型(没有残差的模型)时,您会得到近乎完美的答案:

anova(lm(value ~ Degrees * variable, macc))

您可以将 Degrees 或 MPH 变量中的一个或两个编码为数字并获得不饱和模型。但它仍然会添加到描述结果的复杂性。

 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))
 macc <- melt(acc, id.var="Degrees")
 anova(lm(value ~ Degrees * variable, macc))

使用 sub 从字符变量中删除“MPH”。我认为有必要对我认为是因子变量的内容使用 as.numeric(as.character()) ,但 sub 操作显然剥离了该因子属性并仅使用 as.numeric 就足够了。

macc$speed <- as.numeric(sub("MPH", "", macc$variable))
anova(lm(value ~ Degrees + speed, macc))
# output omitted
anova(lm(value ~ Degrees * speed, macc))
#-------------------
    Analysis of Variance Table

Response: value
              Df   Sum Sq  Mean Sq F value   Pr(>F)    
Degrees        1 0.016827 0.016827  16.904 0.003384 ** 
speed          1 0.048735 0.048735  48.959 0.000113 ***
Degrees:speed  1 0.006367 0.006367   6.396 0.035309 *  
Residuals      8 0.007963 0.000995                     
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

The conventional answer would be:

macc <- melt(acc, id.var="Degrees")
lm(value ~ Degrees + variable, macc)
anova(lm(value ~ Degrees + variable, macc))

And all that remains is constructing a proper description of the results. (Notice that I used "+" instead of "*"). You get a nearly perfect answer when constructing a saturated model (one with no residuals) when using the interaction model:

anova(lm(value ~ Degrees * variable, macc))

You could have coded either or both of Degrees or MPH variables as numeric and gotten an unsaturated model.But it would still have added to the complexity of describing the result.

 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))
 macc <- melt(acc, id.var="Degrees")
 anova(lm(value ~ Degrees * variable, macc))

Using sub to remove the "MPH" from the character variables. I thought it would be necessary to use as.numeric(as.character()) on what I thought would be a factor variable, but the sub operation apparently stripped the factor attribute and just using as.numeric was sufficient.

macc$speed <- as.numeric(sub("MPH", "", macc$variable))
anova(lm(value ~ Degrees + speed, macc))
# output omitted
anova(lm(value ~ Degrees * speed, macc))
#-------------------
    Analysis of Variance Table

Response: value
              Df   Sum Sq  Mean Sq F value   Pr(>F)    
Degrees        1 0.016827 0.016827  16.904 0.003384 ** 
speed          1 0.048735 0.048735  48.959 0.000113 ***
Degrees:speed  1 0.006367 0.006367   6.396 0.035309 *  
Residuals      8 0.007963 0.000995                     
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文