\begin{Schunk}
\begin{Sinput}
 ##' Tell this function the condition row to use,
 ##' and it creates a batch of simulations
 runOneCondition <- function(i, conds){
     x <- conds[i, ]
     result.list <- lapply(1:x$maxReps, runOneSim, 
                   N = x$N, M = x$M, SD = x$SD)
     do.call("rbind", result.list)
  }
 allResults <- lapply(1:NROW(conds), runOneCondition, conds)
 ## Each sample drawn from a particular population is a "case" (like
 ## subjects).  We can easily combine our list of results as a single
 ## data set for analysis
 output <- do.call(rbind, allResults)
 head(output, 30)
\end{Sinput}
\begin{Soutput}
    rep     pvalue reject     N       M    SD
N     1 0.42719499      0 30:30 100:100 10:20
N1    2 0.31725809      0 30:30 100:100 10:20
N2    3 0.57996600      0 30:30 100:100 10:20
N3    1 0.74422299      0 30:30 100:100 15:15
N11   2 0.41279370      0 30:30 100:100 15:15
N21   3 0.63699226      0 30:30 100:100 15:15
N4    1 0.55661831      0 30:30 100:100 20:10
N12   2 0.61536653      0 30:30 100:100 20:10
N22   3 0.83029046      0 30:30 100:100 20:10
N5    1 0.86315193      0 40:20 100:100 10:20
N13   2 0.18103430      0 40:20 100:100 10:20
N23   3 0.09913700      0 40:20 100:100 10:20
N6    1 0.80104357      0 40:20 100:100 15:15
N14   2 0.08603419      0 40:20 100:100 15:15
N24   3 0.04868749      1 40:20 100:100 15:15
N7    1 0.66700548      0 40:20 100:100 20:10
N15   2 0.25679324      0 40:20 100:100 20:10
N25   3 0.93516193      0 40:20 100:100 20:10
\end{Soutput}
\begin{Sinput}
 ## Finally, we are ready to run several replications in each condition.
 conds$maxReps <- 1000
 conds
\end{Sinput}
\begin{Soutput}
  maxReps    SD     N       M
1    1000 10:20 30:30 100:100
2    1000 15:15 30:30 100:100
3    1000 20:10 30:30 100:100
4    1000 10:20 40:20 100:100
5    1000 15:15 40:20 100:100
6    1000 20:10 40:20 100:100
\end{Soutput}
\begin{Sinput}
 ## Our Monte Carlo study will take a few moments to run
 set.seed(123)
 bigResults <- lapply(1:NROW(conds), runOneCondition, conds)
 stackedResults <- do.call(rbind, bigResults)
 ## Now summarize the rejection rate for each condition
 output <- aggregate(reject ~ N + SD, data = stackedResults, FUN = mean)
 names(output) <- c("N", "SD", "Type.I.Rate")
 output
\end{Sinput}
\begin{Soutput}
      N    SD Type.I.Rate
1 30:30 10:20       0.044
2 40:20 10:20       0.108
3 30:30 15:15       0.053
4 40:20 15:15       0.050
5 30:30 20:10       0.041
6 40:20 20:10       0.012
\end{Soutput}
\end{Schunk}
