I would like to use GLM and Elastic Net to select those relevant features + build a linear regression model (i.e., both prediction and understanding, so it would be better to be left with relatively few parameters). The output is continuous. It's $20000$ genes per $50$ cases. I've been reading about the glmnet
package, but I'm not 100% sure about the steps to follow:
Perform CV to choose lambda:
cv <- cv.glmnet(x,y,alpha=0.5)
(Q1) given the input data, would you choose a different alpha value?
(Q2) do I need to do something else before build the model?Fit the model:
model=glmnet(x,y,type.gaussian="covariance",lambda=cv$lambda.min)
(Q3) anything better than "covariance"?
(Q4) If lambda was chosen by CV, why does this step neednlambda=
?
(Q5) is it better to uselambda.min
orlambda.1se
?Obtain the coefficients, to see which parameters have fallen out ("."):
predict(model, type="coefficients")
In the help page there are many
predict
methods (e.g.,predict.fishnet
,predict.glmnet
,predict.lognet
, etc). But any "plain" predict as I saw on an example.
(Q6) Should I usepredict
orpredict.glmnet
or other?
Despite what I've read about regularization methods, I'm quite new in R and in these statistical packages, so it's difficult to be sure if I'm adapting my problem to the code. Any suggestions will be welcomed.
UPDATE
Based on "As previously noted, an object of class train contains an element called finalModel
, which is the fitted model with the tuning parameter values selected by resampling. This object can be used in the traditional way to generate predictions for new samples, using that model's
predict function."
Using caret
to tune both alpha and lambda:
trc = trainControl(method=cv, number=10)
fitM = train(x, y, trControl = trC, method="glmnet")
Does fitM
replace previous step 2? If so, how to specify the glmnet options (type.gaussian="naive",lambda=cv$lambda.min/1se
) now?
And the following predict
step, can I replace model
to fitM
?
If I do
trc = trainControl(method=cv, number=10)
fitM = train(x, y, trControl = trC, method="glmnet")
predict(fitM$finalModel, type="coefficients")
does it make sense at all or am I incorrectly mixing both package vocabulary?