Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Coefficient to be Negative in R lm

Tags:

r

regression

lm

I want to force one of the coefficients in my model to be less than or equal to zero.

The nnls package allows you to set all coefficients equal to or greater than zero, but I'm at a loss as to how to specify a specific coefficient to be less than zero.

Any help would be greatly appreciated.

like image 637
Burton Guster Avatar asked Jan 22 '26 01:01

Burton Guster


1 Answers

The function nnnpls in the same package is "an implementation of least squares with non-negative and non-positive constraints".

Its third argument, con, allows one to specify which coefficients should be non-positive:

numeric vector of length m where element i is negative if and only if element i of the solution vector x should be constrained to non-positive, as opposed to non-negative, values.

like image 187
NPE Avatar answered Jan 24 '26 17:01

NPE