[R] Forcing a negative slope in linear regression?
Bill.Venables at csiro.au
Bill.Venables at csiro.au
Wed Jun 1 04:37:55 CEST 2011
If you want to go ahead with this in cold blood, you might look at the 'nnls' package.
It fits regressions with non-negative coefficients. This might seem like the very opposite of what you want, but it essentially gets you there. You have to be prepared for the coefficient to go to zero though, if according to the data it really needs to be positive to minimise the residual SSQ.
Here's what you do:
* For any predictor, x, for which you want the regression coefficient to be non-positive, use -x as the predictor in the model. Think about it.
* (The real trick) For any predictor, z, whose coefficient is not to be constrained at all, put *both* z and -z in as predictors. The algorithm will choose only one of them.
nnls is now quite an old package and the interface is rather klunky, but the method is still OK.
Bill Venables.
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Jeff Newmiller
Sent: Wednesday, 1 June 2011 11:38 AM
To: J S; r-help at r-project.org
Subject: Re: [R] Forcing a negative slope in linear regression?
If you force the slope, it is no longer a regression, so no. It is best to add those other dependent variables to the regression and evaluate whether their presence causes the fit to improve and yield signs of coefficients that match what you expect.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
J S <yulya258 at gmail.com> wrote:
Dear forum members,
How can I force a negative slope in a linear regression even though the
slope might be positive?
I will need it for the purpose of determining the trend due reasons other
than biological because the biological (genetic) trend is not positive for
these data.
Thanks. Julia
Example of the data:
[1] 1.254 1.235 1.261 0.952 1.202 1.152 0.801 0.424 0.330 0.251 0.229 0.246
[13] 0.414 0.494 0.578 0.628 0.514 0.594 0.827 0.812 0.629 0.928 0.707 0.976
[25] 1.099 1.039 1.272 1.398 1.926 1.987 2.132 1.644 2.174 2.453 2.392 3.002
[37] 3.352 2.410 2.206 2.692 2.653 1.604 2.536 3.070 3.137 4.187 4.803 4.575
[49] 4.580 3.779 4.201 5.685 4.915 5.929 5.474 6.140 5.182 5.524 5.848 5.830
[61] 5.800 7.517 6.422
[[alternative HTML version deleted]]
_____________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list