14
$\begingroup$

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).

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – Backlin Oct 8 '12 at 7:28
  • 1
    $\begingroup$ 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... $\endgroup$ – Joris Meys Oct 8 '12 at 8:48
  • $\begingroup$ Sorry about that. Non negative means all coefficients are positive. I tried using the package glmnet but that only solves for the general case. $\endgroup$ – gbh. Oct 16 '12 at 14:24
12
$\begingroup$

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

| cite | improve this answer | |
$\endgroup$
8
$\begingroup$

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.

| cite | improve this answer | |
$\endgroup$
5
$\begingroup$

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.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.