[Scipy-svn] r5593 - trunk/scipy/stats

scipy-svn@scip... scipy-svn@scip...
Tue Feb 24 13:53:21 CST 2009


Author: josef
Date: 2009-02-24 13:53:18 -0600 (Tue, 24 Feb 2009)
New Revision: 5593

Modified:
   trunk/scipy/stats/stats.py
Log:
small rewrite of stats.linregress

Modified: trunk/scipy/stats/stats.py
===================================================================
--- trunk/scipy/stats/stats.py	2009-02-24 00:52:17 UTC (rev 5592)
+++ trunk/scipy/stats/stats.py	2009-02-24 19:53:18 UTC (rev 5593)
@@ -1768,9 +1768,11 @@
     n = len(x)
     xmean = np.mean(x,None)
     ymean = np.mean(y,None)
-    xm,ym = x-xmean, y-ymean
-    r_num = np.add.reduce(xm*ym)
-    r_den = np.sqrt(ss(xm)*ss(ym))
+
+    # 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:
@@ -1779,10 +1781,10 @@
     #z = 0.5*log((1.0+r+TINY)/(1.0-r+TINY))
     df = n-2
     t = r*np.sqrt(df/((1.0-r+TINY)*(1.0+r+TINY)))
-    prob = betai(0.5*df,0.5,df/(df+t*t))
-    slope = r_num / ss(xm)
+    prob = distributions.t.sf(np.abs(t),df)*2
+    slope = r_num / ssxm
     intercept = ymean - slope*xmean
-    sterrest = np.sqrt((1-r*r)*ss(ym) / ss(xm) / df)
+    sterrest = np.sqrt((1-r*r)*ssym / ssxm / df)
     return slope, intercept, r, prob, sterrest
 
 



More information about the Scipy-svn mailing list