[Scipy-svn] r6976 - in trunk/scipy/stats: . tests

scipy-svn@scip... scipy-svn@scip...
Mon Nov 29 08:46:01 CST 2010


Author: rgommers
Date: 2010-11-29 08:46:00 -0600 (Mon, 29 Nov 2010)
New Revision: 6976

Modified:
   trunk/scipy/stats/mstats_basic.py
   trunk/scipy/stats/tests/test_mstats_basic.py
Log:
ENH: update mstats to use new zmap/zscore, remove z/zs. Closes #1195.

The plain stats functions zmap and zscore now also handle masked arrays, and
they support more functionality that the versions that were removed.

Modified: trunk/scipy/stats/mstats_basic.py
===================================================================
--- trunk/scipy/stats/mstats_basic.py	2010-11-29 00:40:49 UTC (rev 6975)
+++ trunk/scipy/stats/mstats_basic.py	2010-11-29 14:46:00 UTC (rev 6976)
@@ -35,7 +35,7 @@
            'ttest_ind','ttest_rel','tvar',
            'var','variation',
            'winsorize',
-           'z','zmap','zs'
+           'zmap', 'zscore'
            ]
 
 import numpy as np
@@ -1933,28 +1933,10 @@
     return s
 sem.__doc__ = stats.sem.__doc__
 
-def z(a, score):
-    a = ma.asarray(a)
-    z = (score-a.mean(None)) / a.std(axis=None, ddof=1)
-    return z
-# where do we get the doc from? stats.z has been removed
-# z.__doc__ = stats.zscore_compare.__doc__
+zmap = stats.zmap
+zscore = stats.zscore
 
-def zs(a):
-    a = ma.asarray(a)
-    mu = a.mean(axis=0)
-    sigma = a.std(axis=0,ddof=0)
-    return (a-mu)/sigma
-zs.__doc__ = stats.zscore.__doc__
 
-def zmap(scores, compare, axis=0):
-    (scores, compare) = (ma.asarray(scores), ma.asarray(compare))
-    mns = compare.mean(axis=axis)
-    sstd = compare.std(axis=0, ddof=0)
-    return (scores - mns) / sstd
-zmap.__doc__ = stats.zmap.__doc__
-
-
 #####--------------------------------------------------------------------------
 #---- --- ANOVA ---
 #####--------------------------------------------------------------------------

Modified: trunk/scipy/stats/tests/test_mstats_basic.py
===================================================================
--- trunk/scipy/stats/tests/test_mstats_basic.py	2010-11-29 00:40:49 UTC (rev 6975)
+++ trunk/scipy/stats/tests/test_mstats_basic.py	2010-11-29 14:46:00 UTC (rev 6976)
@@ -451,26 +451,28 @@
         y = mstats.sem(self.testcase)
         assert_almost_equal(y,0.6454972244)
 
-    def test_z(self):
+    def test_zmap(self):
         """
-        not in R, so used
-        (10-mean(testcase,axis=0))/sqrt(var(testcase)*3/4)
+        not in R, so tested by using
+        (testcase[i]-mean(testcase,axis=0))/sqrt(var(testcase)*3/4)
         """
-        y = mstats.z(self.testcase, ma.array(self.testcase).mean())
-        assert_almost_equal(y,0.0)
+        y = mstats.zmap(self.testcase, self.testcase)
+        desired_unmaskedvals = ([-1.3416407864999, -0.44721359549996 ,
+                                 0.44721359549996 , 1.3416407864999])
+        assert_array_almost_equal(desired_unmaskedvals,
+                                  y.data[y.mask==False], decimal=12)
 
-    def test_zs(self):
+    def test_zscore(self):
         """
         not in R, so tested by using
         (testcase[i]-mean(testcase,axis=0))/sqrt(var(testcase)*3/4)
         """
-        y = mstats.zs(self.testcase)
+        y = mstats.zscore(self.testcase)
         desired = ma.fix_invalid([-1.3416407864999, -0.44721359549996 ,
                                   0.44721359549996 , 1.3416407864999, np.nan])
-        assert_almost_equal(desired,y,decimal=12)
+        assert_almost_equal(desired, y, decimal=12)
 
 
-
 class TestMisc(TestCase):
     #
     def test_obrientransform(self):



More information about the Scipy-svn mailing list