Solved – Two intercept coefficients in glmnet output

glmnetinterceptr

I am not sure I understand why glmnet returns 2 intercepts in its result.
If model matrix already has intercept column, why do we need another intercept for the model?

> mm = model.matrix(...)
> colnames(mm)
 [1] "(Intercept)"  "v1" "v2"....

> model.fit = glmnet(mm, resp, standardize=FALSE, family='binomial', nlambda = 10)
> coef(model.fit, s= 1e-05)
  48 x 1 sparse Matrix of class "dgCMatrix"                        1
  (Intercept)        5.9487109234
  (Intercept)        .           
  v1        0.2580378293
  v2       -0.4693849121
  .....

Best Answer

You need to drop the intercept (the vector of 1's) from the mm matrix since the glmnet package automatically demeans the data and reports the intercept term by default.

Alternatively, you can use the intercept parameter to glmnet (TRUE by default).