[R] Forcing a negative slope in linear regression?
Rolf Turner
rolf.turner at xtra.co.nz
Wed Jun 1 04:40:04 CEST 2011
(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]]
More information about the R-help
mailing list