title: Variable Selection with mgcv
body: <p>Is there a way of automating variable selection of a GAM in R, similar to step?  I've read the documentation of <code>step.gam</code> and <code>selection.gam</code>, but I've yet to see a answer with code that works.  Additionally, I've tried <code>method= "REML"</code> and <code>select = TRUE</code>, but neither remove insignificant variables from the model.</p>
  
  <p>I've theorized that I could create a step model and then use those variables to create the GAM, but that does not seem computationally efficient.</p>
  
  <p>Example:</p>
  
  <pre><code>library(mgcv)
  
  set.seed(0)
  dat &lt;- data.frame(rsp = rnorm(100, 0, 1), 
                    pred1 = rnorm(100, 10, 1), 
                    pred2 = rnorm(100, 0, 1), 
                    pred3 = rnorm(100, 0, 1), 
                    pred4 = rnorm(100, 0, 1))
  
  model &lt;- gam(rsp ~ s(pred1) + s(pred2) + s(pred3) + s(pred4),
               data = dat, method = "REML", select = TRUE)
  
  summary(model)
  
  #Family: gaussian 
  #Link function: identity 
  
  #Formula:
  #rsp ~ s(pred1) + s(pred2) + s(pred3) + s(pred4)
  
  #Parametric coefficients:
  #            Estimate Std. Error t value Pr(&gt;|t|)
  #(Intercept)  0.02267    0.08426   0.269    0.788
  
  #Approximate significance of smooth terms:
  #            edf Ref.df     F p-value  
  #s(pred1) 0.8770      9 0.212  0.1174  
  #s(pred2) 1.8613      9 0.638  0.0374 *
  #s(pred3) 0.5439      9 0.133  0.1406  
  #s(pred4) 0.4504      9 0.091  0.1775  
  ---
  #Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
  
  #R-sq.(adj) =  0.0887   Deviance explained = 12.3%
  #-REML = 129.06  Scale est. = 0.70996   n = 100
  </code></pre>