Is it possible to do a lasso model with both penalized and un-penalized covariates? That is, I want to do an estimate with Y ~ gamma * X + beta * Z
, where X is a n*p
penalized features and Z a n*q
un-penalized covariates of continues or factor variables.
1 Answer
One way to learn about the functionality of an R package is to look at its documentation.
The command ?glmnet
takes us to the help page for the function. Here, we are presented with a number of options pertaining to the function, and an exhaustive list of the additional arguments one may pass to it.
Of particular interest is this entry:
penalty.factor
Separate penalty factors can be applied to each coefficient. This is a number that multiplies lambda to allow differential shrinkage. Can be 0 for some variables, which implies no shrinkage, and that variable is always included in the model. Default is 1 for all variables (and implicitly infinity for variables listed in exclude). Note: the penalty factors are internally rescaled to sum to nvars, and the lambda sequence will reflect this change.