简体   繁体   English

R错误df中的1 Way Anova测试

[英]1 Way Anova Test in R incorrect df

I want to run an anova test in R to find out if there's a difference in the number of weeks of each brand. 我想在R中进行anova测试,以了解每个品牌的周数是否存在差异。 My code is as follows: 我的代码如下:

weeks = c(100,96,92,96,92,76,80,75,84,82,108,100,96,98,100)
brand = c('a','a','a','a','a','b','b','b','b','b','c','c','c','c','c')
battery.exp = data.frame(brand, weeks)
test.1 = aov(battery.exp$weeks~battery.exp$brand)
summary(test.1)

I'm getting incorrect results in the summary. 摘要中显示错误结果。 The df of the brand should be 2, but my output says 3. Does anyone know why I would get incorrect results in my anova test? 品牌的df应该为2,但我的输出为3。有人知道为什么在方差分析中会得到不正确的结果吗? I've also tried to replace the second to last line with the following: 我还尝试用以下内容替换倒数第二行:

test.1 = aov(battery.exp$weeks~factor(battery.exp$brand))

but that also didn't solve the problem. 但这也不能解决问题。 Any suggestions on how to fix? 有关如何修复的任何建议?

The default is to use a model with an intercept which means you need to use a reference level for your categorical variable so you only have two free parameters. 默认是使用带有截距的模型,这意味着您需要为分类变量使用参考级别,因此您只有两个自由参数。 If you don't want to use an intercept, you can explicitly request an intercept free model with 如果您不想使用拦截,则可以使用

summary(aov(weeks~brand-1, battery.exp))

(note the -1 in the formula) (请注意公式中的-1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM