[SciPy-User] scipy.stats.linregress

josef.pktd at gmail.com josef.pktd at gmail.com
Tue Feb 12 07:37:56 EST 2013


On Tue, Feb 12, 2013 at 7:19 AM, Jerome Kieffer <Jerome.Kieffer at esrf.fr> wrote:
> On Tue, 12 Feb 2013 11:55:31 +0100
> Daπid <davidmenhur at gmail.com> wrote:
>
>> This parameter is R**2, the square of R. You are computing it using the
>> squares of the residuals, so everything should be positive. If you get r
>> negative, something  has gone terribly wrong.
>
> In [3]: scipy.stats.linregress([1,2,3],[3,2,1])
> Out[3]: (-1.0, 4.0, -1.0, 9.0031759825137669e-11, 0.0)
>
> I am not very confident in my knowledge in statistics but here R = -1 and it does not look like an error.
> I implemented a method to perform thousands of linear regression and few of them returned -1.00001 (or so) which later gave NaN as stderr.
>
> so either the test should be:
> if (r*r > 1.0): r = r/abs(r)
> or:
> if (r > 1.0): r = 1
> elif (r < -1.0): r = -1

The correlation coefficient that is reported is the signed
correlation, the docstring has an example that takes the square to get
R_squared.

I don't know whether it's the R_squared, I need to check.

But because r is signed we should have the check r<-1 then -1

Josef

>
> Cheers,
>
> --
> Jérôme Kieffer
> On-Line Data analysis / Software Group
> ISDD / ESRF
> tel +33 476 882 445
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user



More information about the SciPy-User mailing list