Tue Feb 12 06:37:56 CST 2013
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 <firstname.lastname@example.org> 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 : scipy.stats.linregress([1,2,3],[3,2,1])
> Out: (-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)
> 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
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
> Jérôme Kieffer
> On-Line Data analysis / Software Group
> ISDD / ESRF
> tel +33 476 882 445
> SciPy-User mailing list
More information about the SciPy-User