[SciPy-User] scipy.stats.linregress

Daπid davidmenhur@gmail....
Tue Feb 12 04:55:31 CST 2013


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.
On Feb 12, 2013 8:59 AM, "Jerome Kieffer" <Jerome.Kieffer@esrf.fr> wrote:

>
> Dear Scipy Community,
>
> I am looking at the scipy.stats.linregress code and see:
>     # average sum of squares:
>     ssxm, ssxym, ssyxm, ssym = np.cov(x, y, bias=1).flat
>     r_num = ssxym
>     r_den = np.sqrt(ssxm*ssym)
>     if r_den == 0.0:
>         r = 0.0
>     else:
>         r = r_num / r_den
>         if (r > 1.0): r = 1.0 # from numerical error
>
> if the slope is negative, the correlation factor R is -1, not one so one
> should add:
>
>         if (r < -1.0): r = -1.0 # from numerical error
>
> or did I completely mis-understood the code ?
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20130212/5c4d2d5b/attachment-0001.html 


More information about the SciPy-User mailing list