Quantcast

Forcing a negative slope in linear regression?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Forcing a negative slope in linear regression?

J S-20
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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Forcing a negative slope in linear regression?

Jeff Newmiller
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:<[hidden email]> 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 <[hidden email]> 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]]

_____________________________________________

[hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Forcing a negative slope in linear regression?

Bill.Venables
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: [hidden email] [mailto:[hidden email]] On Behalf Of Jeff Newmiller
Sent: Wednesday, 1 June 2011 11:38 AM
To: J S; [hidden email]
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:<[hidden email]> 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 <[hidden email]> 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]]

_____________________________________________

[hidden email] 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]]

______________________________________________
[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Forcing a negative slope in linear regression?

Rolf Turner-3
In reply to this post by J S-20

(1)  You can easily force the slope to take on a *particular* value,
positive or negative, by using offset().  However just to constrain
the value of the slope to be less than or equal to 0 you'd have to
do a constrained optimization of the sum of squares.  Not hard to
do, but probably (almost surely) unwise.  If the data are telling you
that the slope is positive, don't argue with them.

Also if you constrain slope <= 0 and the data want the slope
to be greater than 0, then the constrained optimum will probably
be at slope == 0.

If you want it to be *less* than 0, you'd have to constrain it with
slope <= - epsilon for some (positive) epsilon.  And then I'd guess
you'd wind up with a slope of -epsilon.  So you might as well fix
the slope at -epsilon and use offset().

But the whole idea makes no sense.  So:  The executive
summary is ``Don't do it.''

(2) Your example data don't make any sense either.  You
present the values of only one variable.  For a regression you
need to have a y-variable and at least one x-variable.  It would
appear that you're not thinking very clearly.

     cheers,

         Rolf Turner

On 01/06/11 11:32, J S 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Forcing a negative slope in linear regression?

John C Frain
In econometrics economic theory often predicts a particular sign for a
slope variable.  One often gets wrong signs on variables but the
coefficients as estimated, in such cases are usually both
statistically and economically insignificant.  In such cases one
generally re-estimates the equation with the variable omitted
(imposing a zero sign.  Perhaps re-estimating with the variable
missing is the simplest solution.  Of course, I agree that if the
variable is significant and of the wrong sign there is something wrong
with the theory or the data.

John

On 1 June 2011 03:40, Rolf Turner <[hidden email]> wrote:

>
> (1)  You can easily force the slope to take on a *particular* value,
> positive or negative, by using offset().  However just to constrain
> the value of the slope to be less than or equal to 0 you'd have to
> do a constrained optimization of the sum of squares.  Not hard to
> do, but probably (almost surely) unwise.  If the data are telling you
> that the slope is positive, don't argue with them.
>
> Also if you constrain slope <= 0 and the data want the slope
> to be greater than 0, then the constrained optimum will probably
> be at slope == 0.
>
> If you want it to be *less* than 0, you'd have to constrain it with
> slope <= - epsilon for some (positive) epsilon.  And then I'd guess
> you'd wind up with a slope of -epsilon.  So you might as well fix
> the slope at -epsilon and use offset().
>
> But the whole idea makes no sense.  So:  The executive
> summary is ``Don't do it.''
>
> (2) Your example data don't make any sense either.  You
> present the values of only one variable.  For a regression you
> need to have a y-variable and at least one x-variable.  It would
> appear that you're not thinking very clearly.
>
>    cheers,
>
>        Rolf Turner
>
> On 01/06/11 11:32, J S 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]]
>
> ______________________________________________
> [hidden email] 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.
>



--
John C Frain
Economics Department
Trinity College Dublin
Dublin 2
Ireland
www.tcd.ie/Economics/staff/frainj/home.html
mailto:[hidden email]
mailto:[hidden email]

______________________________________________
[hidden email] 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.
Loading...