Skip to main content
Statistics LibreTexts

11.4: Simulating one-factor ANOVAs

  • Page ID
    7957
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    The following builds simulated data for a one-factor ANOVA, appropriate for a between subjects design. We build the data frame containg a column for the group factor levels, and a column for the DV. Then, we run the ANOVA an print it out.

    library(xtable)
    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))
    knitr::kable(xtable(aov_results))
    Df Sum Sq Mean Sq F value Pr(>F)
    groups 2 1187.127 593.5635 2.683555 F)" style="vertical-align:middle;">0.0699765
    Residuals 297 65692.093 221.1855 NA F)" style="vertical-align:middle;">NA

    In this next example, we simulate the same design 100 times, save the \(p\)-values, and the determine the proportion of significant simulations.

    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
    0.07

    This page titled 11.4: Simulating one-factor ANOVAs is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by Matthew J. C. Crump via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?