title: simulation study using AIC
body: <p>I have to code a simulation study in R. So, I have X1,...,X15~N(0,1) explanatory variables and Y~N(2+2*X1+0.8*X2­1.2*X15, 1) and I need to simulate n=100 values and repeat that for iter=100 times. Then, for each linear model created I have to calculate the AIC­values and, finally, find the best model. The problem is that I can't figure out how to do that for item=100 times. I wrote the code for 1 simulation, which is the following:</p>
  
  <pre><code>set.seed(123)
  n&lt;‐100
  p&lt;‐15
  iter&lt;‐100 X&lt;‐matrix(rep(NA,n*p),ncol=p) for (j in 1:p) {
  X[,j]&lt;‐rnorm(n = 100, mean = 0, sd = 1) }
  mu&lt;‐(2+2*X[,1])+(0.8*X[,2])‐(1.2*X[,15]) Y&lt;‐rnorm(n = 100, mean = mu , sd = 1) 
  sim&lt;‐data.frame(Y,X)
  d&lt;‐lm(Y~X, data = sim)
  </code></pre>
  
  <p>But how I do the rest I have to do, i.e.the 100 simulations and the calculations of AIC? I'm really new to R, so I am quite confused.</p>