implement lasso Regression in GAMs in R Hello I search a way to select variables in a gam function R by using Lasso Regression.
I already fitted a model
gam(y~x) with x containing parametric and nonparametric variables. Now I want to exclude not significant variables from x via Lasso
 A: It's not the Lasso, but it has the same effect; Marra & Wood (2011) proposed two options for this and describe several other ways to do feature selection in GAMs.
Both proposals involve modifying the usual ridge/wiggliness penalty(ies), which do not affect the perfectly smooth basis functions (the null space of the basis), such that the model can penalise the perfectly smooth parts of the basis and thus shrink terms out of the model entirely.
The two proposed options are:


*

*For thin plate and cubic regression splines, Marra & Wood (2011) suggest using an eigendecomposition of the penalty matrix, where the perfectly smooth basis functions have an eigenvalue equal to zero (which is why they don't contribute to the usual wiggliness penalty). They propose that a small value be added to the zero eigenvalues such that they now are also affected by the wiggliness penalty.
The small value that is added implies that the wiggly parts of the basis will get shrunk more than the perfectly smooth parts.
In mgcv you can choose to use these types of smoother via the bs argument to s(), te() etc. For shrinkage thin plate splines use bs = 'ts' and for the cubic spline equivalent use bs = 'cs'.

*The second option, the double penalty method and which has somewhat better performance, is to impose a second penalty that affect only the perfectly smooth terms. Now there are two penalties, one controlling the wiggliness and one controlling the smooth parts of the basis, which means that the linear terms in the model can be shrunk from the model also.
This implies that you want to shrink the wiggly and smooth parts of the basis in the same way.
You add this to the model in mgcv by using the select = TRUE argument to gam() etc. This means that you have to turn this method on for all smooth terms in the model, whereas the shrinkage smooth option above allows you to selectively decide which terms should be subject to feature selection. The double penalty approach also means that two smoothness parameters per smooth (instead of the usual one) need to be estimated/selected during fitting.
Marra, G., Wood, S.N., 2011. Practical variable selection for generalized additive models. Comput. Stat. Data Anal. 55, 2372–2387. https://doi.org/10.1016/j.csda.2011.02.004
