[SciPy-User] scipy.stats.linregress
Jerome Kieffer
Jerome.Kieffer at esrf.fr
Tue Feb 12 07:19:04 EST 2013
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
Cheers,
--
Jérôme Kieffer
On-Line Data analysis / Software Group
ISDD / ESRF
tel +33 476 882 445
More information about the SciPy-User
mailing list