0

I am using glmnet to train the logistic regression model and then try to obtain the coefficients with the specific lambda. I used the simple example here:

load("BinomialExample.RData")

fit = glmnet(x, y, family = "binomial")
coef(fit, s = c(0.05,0.01))

I have checked the values of fit$lambda, however, I could not find the specific values of 0.05 or 0.01 in fit$lambda. So how could coef return the coefficients with a lambda not in the fit$lambda vector.

Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
  • Questions about *programming, debugging, or performing routine operations within a statistical computing platform* are [off-topic](http://stats.stackexchange.com/help/on-topic) here. – T.E.G. Jan 23 '17 at 03:01
  • You can't. If you really need to do so, consider linearly interpolating between the next largest and next smallest values of lambda. – Matthew Drury Jan 23 '17 at 03:50

1 Answers1

0

This is explained in the help for coef.glmnet, specifically the exact argument:

exact

This argument is relevant only when predictions are made at values of s (lambda) different from those used in the fitting of the original model. If exact=FALSE (default), then the predict function uses linear interpolation to make predictions for values of s (lambda) that do not coincide with those used in the fitting algorithm. While this is often a good approximation, it can sometimes be a bit coarse. With exact=TRUE, these different values of s are merged (and sorted) with object$lambda, and the model is refit before predictions are made.

Community
  • 1
  • 1
Hong Ooi
  • 56,353
  • 13
  • 134
  • 187