简体   繁体   English

R:2向Anova与ez软件包不匹配

[英]R: 2-way Anova does not match with ez package

I'm using the ez package however I realized that the results sometimes does not match the anova function. 我正在使用ez软件包,但是我意识到结果有时与anova函数不匹配。 I'm wondering what I'm doing wrong. 我想知道我在做什么错。

options(contrasts=c("contr.sum","contr.poly")) 
datafilename="https://docs.google.com/spreadsheets/d/1PNHSBMUdPnB_mnP_WrcxYYiwCwN8KHL2Q57KoAoWdAY/pub?gid=0&single=true&output=csv"
data.ex2=read.csv(datafilename,header=1,stringsAsFactors=FALSE) 
data.ex2                                     
aov.ex2 = aov(value~Treat*Gender,data=data.ex2  )         
summary(aov.ex2)  

### testing the ez package now 

library(ez) 

A = ezANOVA(
  data = data.ex2
  , dv = value
  , wid = ID
  , between = .(Treat,Gender)
  ,return_aov=TRUE
  , type = 3
)

print (A$ANOVA)
  • when I use the example given on another website the results matches perfectly so I'm wondering if there is something I'm doing wrong with my table. 当我使用另一个网站上给出的示例时,结果完全匹配,所以我想知道我的桌子是否做错了什么。 The example that matches if from this dataset here. 与此处匹配的示例。

    datafilename="http://personality-project.org/r/datasets/R.appendix2.data" datafilename = “http://personality-project.org/r/datasets/R.appendix2.data”

thanks! 谢谢!

You have multiple observations of ID per each grouping. 每个分组对ID都有多个观察值。 This is mentioned in the warning when running your code, and it says that the values have been collapsed to their mean. 在运行代码时的警告中提到了这一点,并指出这些值已折叠至其平均值。 So, under the hood it would be doing the following, 因此,在后台执行以下操作,

library(plyr)
collapsed <- ddply(data.ex2, .(ID, Treat, Gender), function(x)
    mean(x[, "value"]))

## the mean value is now in column `V1`
aov(V1 ~ Treat*Gender, data=collapsed)

Ok I finally figured it out. 好吧,我终于明白了。 Needed one last command. 需要最后一个命令。

drop1(aov.ex2, .~., test="F")

now it works, for reference I got this info from here: 现在它可以工作了,作为参考,我从这里得到了这个信息:

http://goanna.cs.rmit.edu.au/~fscholer/anova.php http://goanna.cs.rmit.edu.au/~fscholer/anova.php

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

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