[SciPy-User] scipy.stats.linregress

josef.pktd@gmai... josef.pktd@gmai...
Tue Feb 12 06:46:02 CST 2013


On Tue, Feb 12, 2013 at 7:37 AM,  <josef.pktd@gmail.com> wrote:
> On Tue, Feb 12, 2013 at 7:19 AM, Jerome Kieffer <Jerome.Kieffer@esrf.fr> wrote:
>> On Tue, 12 Feb 2013 11:55:31 +0100
>> Daπid <davidmenhur@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.

>>> sm.OLS([1,2,3],sm.add_constant([3.1,2,1])).fit().rsquared
0.99924471299093653

>>> stats.linregress([3.1,2,1], [1,2,3])[2]
-0.99962228516121865
>>> stats.linregress([3.1,2,1], [1,2,3])[2]**2
0.99924471299093676

Josef
Josef
>
> 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@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user


More information about the SciPy-User mailing list