[SciPy-User] scipy.stats.linregress
Daπid
davidmenhur at gmail.com
Tue Feb 12 05:55:31 EST 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 at 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 at 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.html>
More information about the SciPy-User
mailing list