# Non negative lasso implementation in R

I am looking for some open source or an existing library I can use. As far as I tell the glmnet package isn't very easily extensible to cover the non negative case. I may be wrong, Any one with any ideas much appreciated.

By non-negative I mean that all coefficients are constrained to be positive (> 0).

• Pardon me for asking, but what exactly do you mean with non-negative lasso? To keep all coefficients > 0 or only allow positive predictions? Googling didn't enlighten me but it sounds like something I'd like to know about. – Backlin Oct 8 '12 at 7:28
• Sorry for closing your question, but it is better asked and answered at www.crossvalidated.com I flagged the question for migration, so the mods will take care of it shortly. This said, please make your question clear and explain exactly what you want. The lasso expert in our research group couldn't possibly figure out what you were aiming at... – Joris Meys Oct 8 '12 at 8:48
• Sorry about that. Non negative means all coefficients are positive. I tried using the package glmnet but that only solves for the general case. – gbh. Oct 16 '12 at 14:24

In glmnet there is the option

lower.limits=0


that you can use and that would be the appropriate way to enforce positivity constraints on the fitted coefficients and if you set parameter alpha to 1 you will be fitting LASSO. In combination with the argument upper.limits you can also specify box constraints. The glmnet package is also much faster than the penalized package, suggested in another answer here.

An Rcpp version of glmnet that can fit the lasso & elastic net with support for positivity and box constraints is also in preparation, and is available for testing at https://github.com/jaredhuling/ordinis

See the penalized package for one option. The Vignette (PDF!) that comes with the package has an example of this in section 3.9.

Essentially set argument positive = TRUE in the call to the penalized() function.

This and this paper demonstrate that under some conditions, hard thresholding of the non-negative least squares solution may perform equivalent or better than L1 regularization (LASSO), in terms of performance. One example is if your design matrix has only non-negative entries, which is often the case.

Worth checking out, as NNLS is very widely supported and will also be easier/faster to solve.