title: Choose model by BIC in a stepwise algorithm after choosing model from glmnet
body: <p>I have data where number of observation <code>n</code> is smaller than number of variables <code>p</code>. The answer variable is binary. For example:</p>
  <pre><code>n &lt;- 10
  p &lt;- 100
  x &lt;- matrix(rnorm(n*p), ncol = p)
  y &lt;- rbinom(n, size = 1, prob = 0.5)
  </code></pre>
  <p>I would like to fit logistic model for this data. So I used the code:</p>
  <pre><code>model &lt;- glmnet(x, y, family = &quot;binomial&quot;, intercept = FALSE)
  </code></pre>
  <p>The function returns 100 models for different $\lambda$ values (penalization parameter in <a href="http://statweb.stanford.edu/%7Etibs/lasso/simple.html" rel="nofollow noreferrer">LASSO</a> regression). I would like to choose the biggest model which also has <code>n - 1</code> parameters or less (so less than number of observations). Let's say the chosen model is for <code>lambda_opt</code>.</p>
  <pre><code>model_one &lt;- glmnet(x, y, family = &quot;binomial&quot;, intercept = FALSE, lambda = lambda_opt)
  </code></pre>
  <p>Now I would like to do the second step - use <code>step</code> function to my model to choose the submodel which will be the best in term of BIC - Bayesian Information Criterion. Unfortunately the <code>step</code> function doesn't work for objects of the <code>glmnet</code> class.</p>
  <pre><code>step(model_one, direction = &quot;backward&quot;, k = log(n))
  </code></pre>
  <p>How can I perform such procedure? Is there any other function for this specific class (<code>glmnet</code>) to do what I want?</p>