N <- 10
groups <- rep(c("A","B","C"), each=10)
DV <- c(rnorm(100,10,15), # means for group A
rnorm(100,10,15), # means for group B
rnorm(100,20,15) # means for group C
)
sim_df<-data.frame(groups,DV)
aov_results <- summary(aov(DV~groups, sim_df))
library(xtable)
knitr::kable(xtable(aov_results))
Section 11.4 Simulating one-factor ANOVAs
The following builds simulated data for a one-factor ANOVA, appropriate for a between subjects design. We build the data frame containing a column for the group factor levels, and a column for the DV. Then, we run the ANOVA and print it out.
Remark 11.4.1. R Code.
| Df | Sum Sq | Mean Sq | F value | Pr(>F) | |
|---|---|---|---|---|---|
| groups | 2 | 111.2747 | 55.63735 | 0.1989719 | 0.8196821 |
| Residuals | 297 | 83048.3738 | 279.62415 | NA | NA |
In this next example, we simulate the same design 100 times, save the \(p\)-values, and then determine the proportion of significant simulations.
Remark 11.4.3. R Code.
N <- 10
save_p<-length(100)
for(i in 1:100){
groups <- rep(c("A","B","C"), each=10)
DV <- c(rnorm(100,10,15), # means for group A
rnorm(100,10,15), # means for group B
rnorm(100,20,15) # means for group C
)
sim_df<-data.frame(groups,DV)
aov_results <- summary(aov(DV~groups, sim_df))
save_p[i]<-aov_results[[1]]$`Pr(>F)`[1]
}
length(save_p[save_p<0.05])/100

