Hopefully, the answer to this question is simple.
Why do I get different results when I am using Anova from the car package and the aov_ez from the afex package?
library(car)
library(afex)
set.seed(100)
dv <- runif(30,90,110)
factor_a <- factor(rep(c("a","b"),15))
factor_b <- factor(rep(c("f","m"),each=15))
id <- factor(1:30)
data <- data.frame(dv,factor_a,factor_b,id)
data$dv[data$factor_b=="f" & data$factor_a=="a"] <- data$dv[data$factor_b=="f" & data$factor_a=="a"] *1.05
aov_ez(dv="dv",between = c("factor_a","factor_b"), id="id",data=data )
Anova(lm(dv~factor_a*factor_b, data=data),type = "III")
Results are different in case of the main effect factor B: Using aov_ez, the main effect is significant, using Anova, the main effect is not significant. How is that possible? In both cases, there is a significant interaction and the F-values are very similar. But the F-values of the main effects differ.
> aov_ez(dv="dv",between = c("factor_a","factor_b"), id="id",data=data )
Contrasts set to contr.sum for the following variables: factor_a, factor_b
Anova Table (Type 3 tests)
Response: dv
Effect df MSE F ges p.value
1 factor_a 1, 26 20.96 4.16 + .14 .05
2 factor_b 1, 26 20.96 0.55 .02 .46
3 factor_a:factor_b 1, 26 20.96 9.03 ** .26 .006
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘+’ 0.1 ‘ ’ 1
> Anova(lm(dv~factor_a*factor_b, data=data),type = "III")
Anova Table (Type III tests)
Response: dv
Sum Sq Df F value Pr(>F)
(Intercept) 89775 1 4282.2927 < 2.2e-16 ***
factor_a 267 1 12.7159 0.001434 **
factor_b 147 1 7.0288 0.013478 *
factor_a:factor_b 189 1 9.0269 0.005822 **
Residuals 545 26
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Because I am quite new using R, which of these two packages I should use. Does anyone know why the results differ?
data$factor_a = "a"
bedata$factor_a == "a"
? $\endgroup$