I have a matrix of 40 observations and 747 variables, which are frequencies with a certain number of zeros. My observations are divided into two groups, resume in the vector "rep_pdrp".

I want to select variables with good discriminant and predictive performance. So I decided to use caret and glmnet R packages as described here : https://quantmacro.wordpress.com/2016/04/26/fitting-elastic-net-model-in-r/

lambda.grid <- seq(0, 100)
alpha.grid <- seq(0, 0.5, length = 6)

trnCtrl = trainControl(
             method = "repeatedCV",
             number = 10,
             repeats = 5)

srchGrd = expand.grid(.alpha = alpha.grid, .lambda = lambda.grid)

my.train <- train(x = data.matrix(my.data),
                  y = rep_pdrp,
                  method = "glmnet",
                  tuneGrid = srchGrd,
                  trControl = trnCtrl,
                  standardize = FALSE,
                  maxit = 1000000)


my.glmnet.model <- my.train$finalModel
sum(coef(my.glmnet.model, s = my.train$bestTune$lambda)!=0)

enter image description here

The "bestTune" parameter are alpha = 0.1 and lambda = 100. When I run again with a larger lambda.grid, it's always the max of lambda which is given in the output... Do you know what is the issue ?

Moreover, all coefficients equal zero, except the intercept. I don't understand why. Have you good an idea of the problem?


closed as unclear what you're asking by gung Dec 17 '18 at 17:20

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Did you use set.seed() function before running feature selection? Without it, you will get different results each time. Also, it is advised to use standardization in the penalized regression. $\endgroup$ – Malgorzata Maciukiewicz Dec 17 '18 at 16:30