Solved – Caret and coefficients (glmnet)

caretglmnet

I am interested in utilizing caret for making inferences on a particular data set. Is it possible to do the following:

  1. produce coefficients of a glmnet model I trained in caret. I would like to use glmnet because of the inherent feature selection as I do not believe glm has it?

  2. other than the ROC metric, is there another metric that I can utilize to asses fit of the model? Such as adjusted $R^2$?

The purpose of this analysis is to derive some inference on the effects of particular variables, rather than for prediction. I just like the caret package because it's been easy to work with thus far using matrices.

Best Answer

Lets say your caret model is called "model". You can access the final glmnet model with model$finalModel. You can then call coef(model$finalModel), etc. You will have to select a value of lambda for which you want coefficients, such as coef(model$finalModel, model$bestTune$.lambda).

Take a look at the summaryFunction parameter for the trainControl function. It will allow you to specify any function you want to minimize (or maximize, see the maximize argument to train), given a predictor and a response.

It might be hard to get at adjusted R^2 in this way, but you could probably get R^2 or something similar.