title: Multiple regression model - model selection by R2
body: <p>I'm working with the following data set and split it in a training data set and a test data set </p>
  
  <pre><code>library(mvdalav)
  data(Penta)
  
  set.seed(321)
  &gt; idx &lt;- sample(1:30, size = 20, replace = F)
  &gt; ptrain &lt;- Penta[idx,]
  &gt; ptest &lt;- Penta[-idx,]
  </code></pre>
  
  <p>I'm running a multiple regression model and I want to select the best model by the step function and R2. So I runned the step: </p>
  
  <pre><code>&gt;selectAIC = step(lm(log.RAI~.,data = ptrain[,-1]),direction="backward")
  &gt; selectAIC$call
  lm(formula = log.RAI ~ S1 + P1 + S2 + L2 + S3 + L3 + L4 + P4, 
      data = ptrain[, -1]) 
  
  </code></pre>
  
  <p>Now I want to do the same but using the R^2 of the model as the criteria for selection. </p>
  
  <p>How can I do this?</p>
  
  <p>kind regards </p>