Yes. Assume we know the variance . Let be the t-test statistic and be the one-way ANOVA statistic. One can reasonably easly show that . Therefore, for a two-sided test corresponding quantiles are equivalent. However, there is no equivalent one-sided test in anova since we are looking at a ‘squared’ value.
# generate some data A = rnorm(10,0) B = rnorm(10,0,2) # change it to the format which we can use for lm C = rbind(cbind(A,1),cbind(B,2)) colnames(C) = c("value", "group") C = data.frame(C) # run tests M1 = t.test(A,B,var.equal = TRUE) M2 = anova(lm(value ~ group ,C)) # compare p-values print(M1$p.value) print(M2["Pr(>F)"])
As we can see, p-values are equal. Note however, that ANOVA is run on the linear model, whereas t-test compares two groups. Although they are equivalent in this context, they are used differently and they are based on different principles.
For ANOVA we brought the data to another format
print(C) value group 1 -1.22252768 1 [...] 10 -1.27401195 1 11 1.64572910 2 [...] 20 -0.79178332 2
so that we can run
lm() method. The model in this example is
We estimate by
lm() and, using
anova(), we test if , which intuitively corresponds to no significance of the group variable. This is a vary different approach than t-test, but, as mentioned in the beginning of this post, it leads to exactly the same result.
Finally, note that in R we also have a function
oneway.test which embraces all these functionalities:
- If number of groups is it runs t-test,
- If number of groups is larger it runs ANOVA,
- In both cases it estimates variances if needed.
So, in this example, we can have
M3 = oneway.test(value ~ group, data=C, var.equal = TRUE)