\begin{Schunk}
\begin{Sinput}
 makeData <- function(rep, N, R, stde = 9, b = c(-3, 5, .5, .5)) {
      require(rockchalk) # will load the package if it's not already loaded
      IQ.cor <- lazyCor(R, 2)
      IQ.M <- c(dadIQ = 100, momIQ = 100)
      IQ.SD <- c(15, 15)
      IQ.cov <- diag(c(15, 15)) %*% IQ.cor %*% diag(c(15, 15))
      dat <- mvrnorm(n = N, mu = IQ.M, Sigma = IQ.cov)
      dat <- as.data.frame(round(dat))
      dat$first <- rbinom(n = N, size = 1, prob = .4)
      dat$IQnoe <- b[1] + b[2]*dat$first + b[3]*dat$dadIQ + b[4]*dat$momIQ 
      dat$IQ <- dat$IQnoe + rnorm(N, m = 0, sd = stde)
      dat$IQ <- round(dat$IQ)
      dat$rep <- rep
      dat
  }
 ## Test it once
 set.seed(123)
 dat <- makeData(1, N = 20, R = .3)
 head(dat)
\end{Sinput}
\begin{Soutput}
  dadIQ momIQ first IQnoe  IQ rep
1    95    91     0  90.0  92   1
2   118   119     1 120.5 120   1
3    86   117     0  98.5  98   1
4   117    94     1 107.5 120   1
5    96    88     0  89.0  87   1
6   112   118     0 112.0 126   1
\end{Soutput}
\begin{Sinput}
 ## To analyze that data and return rejection decisions
 getDecision <- function(data, alpha = .05) {
      ## run a regression on sample data
      mod <- lm(IQ ~ first + momIQ + dadIQ, data = data)
      ## return decisions about whether null was rejected for each slope
      summary(mod)$coef[2:4, 4] < alpha
  }
 ## Test it once (on the data we just generated)
 getDecision(data = dat)
\end{Sinput}
\begin{Soutput}
first momIQ dadIQ 
FALSE  TRUE  TRUE 
\end{Soutput}
\begin{Sinput}
 ## Test it on 5 replications to see the format of the output
 dataList <- lapply(1:5, makeData, N = 100, R = 0.30)
 lapply(dataList, head)
\end{Sinput}
\begin{Soutput}
[[1]]
  dadIQ momIQ first IQnoe  IQ rep
1   115    74     1  96.5  99   1
2   118   106     0 109.0 120   1
3    83   101     1  94.0  82   1
4   107    86     0  93.5  99   1
5   103   101     1 104.0  99   1
6    97   103     1 102.0 108   1

[[2]]
  dadIQ momIQ first IQnoe  IQ rep
1   119   124     0 118.5 114   2
2    90   113     0  98.5  96   2
3    95    87     1  93.0  97   2
4   129   129     0 126.0 121   2
5   133   107     1 122.0 123   2
6    94   101     0  94.5  77   2

[[3]]
  dadIQ momIQ first IQnoe  IQ rep
1    84    76     0  77.0  76   3
2   120    91     0 102.5 101   3
3    87   120     0 100.5 113   3
4   102    97     1 101.5 110   3
5   108   103     0 102.5  88   3
6   102   118     1 112.0 114   3

[[4]]
  dadIQ momIQ first IQnoe  IQ rep
1   105    79     0  89.0  85   4
2   119   115     1 119.0 107   4
3    65   122     0  90.5 102   4
4   103    95     0  96.0  83   4
5   118    90     1 106.0  98   4
6   107   105     1 108.0 114   4

[[5]]
  dadIQ momIQ first IQnoe  IQ rep
1   108    85     0  93.5  96   5
2    90    87     1  90.5  92   5
3    93    63     1  80.0  77   5
4   118   108     0 110.0 100   5
5    79    77     0  75.0  77   5
6   110   122     1 118.0  99   5
\end{Soutput}
\begin{Sinput}
 do.call(rbind, lapply(dataList, getDecision))
\end{Sinput}
\begin{Soutput}
     first momIQ dadIQ
[1,]  TRUE  TRUE  TRUE
[2,]  TRUE  TRUE  TRUE
[3,]  TRUE  TRUE  TRUE
[4,]  TRUE  TRUE  TRUE
[5,]  TRUE  TRUE  TRUE
\end{Soutput}
\begin{Sinput}
 ## Define a function that gets rejections for nReps replications per
 ## condition
 runCond <- function(nReps, N, R) {
      ## generate nReps data sets
      dataList <- lapply(1:nReps, makeData, N = N, R = R)
      ## run regression and get rejection decisions for each data set
      out <- data.frame(do.call(rbind, lapply(dataList, getDecision)))
      ## record conditions
      out$N <- N
      out$R <- R
      ## return results
      out
  }
 ## Test it on 10 replications
 runCond(nReps = 10, N = 100, R = .3)
\end{Sinput}
\begin{Soutput}
   first momIQ dadIQ   N   R
1  FALSE  TRUE  TRUE 100 0.3
2   TRUE  TRUE  TRUE 100 0.3
3   TRUE  TRUE  TRUE 100 0.3
4   TRUE  TRUE  TRUE 100 0.3
5  FALSE  TRUE  TRUE 100 0.3
6  FALSE  TRUE  TRUE 100 0.3
7   TRUE  TRUE  TRUE 100 0.3
8   TRUE  TRUE  TRUE 100 0.3
9   TRUE  TRUE  TRUE 100 0.3
10 FALSE  TRUE  TRUE 100 0.3
\end{Soutput}
\end{Schunk}
