Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we specify a custom lambda sequence to glmnet

I am new to the glmnet package in R, and wanted to specify a lambda function based on the suggestion in a published research paper to the glmnet.cv function. The documentation suggests that we can supply a decreasing sequence of lambdas as a parameter. However, in the documentation there are no examples of how to do this.

It would be very grateful if someone can suggest how to go about doing this. Do I pass a vector of 100 odd values (default value for nlambda) to the function? What restrictions should be there for the min and max value of this vector, if any? Also, are their things to keep in mind regarding nvars, nobs etc. while specifying the vector?

Thanks in advance.

like image 743
user2758050 Avatar asked Mar 18 '23 15:03

user2758050


1 Answers

You can define a grid like this :

    grid=10^seq(10,-2,length=100) ##get lambda sequence
    ridge_mod=glmnet(x,y,alpha=0,lambda=grid)
like image 127
Amrita Sawant Avatar answered Mar 20 '23 04:03

Amrita Sawant