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

scipy-svn@scip... scipy-svn@scip...
Sat Nov 27 22:52:01 CST 2010

```Author: rgommers
Date: 2010-11-27 22:52:01 -0600 (Sat, 27 Nov 2010)
New Revision: 6952

Modified:
trunk/scipy/stats/mstats_basic.py
trunk/scipy/stats/tests/test_mstats_basic.py
Log:
BUG: fix mstats.plotting_positions for integer inputs, and improve docstring.

Closes #1256.

Modified: trunk/scipy/stats/mstats_basic.py
===================================================================
--- trunk/scipy/stats/mstats_basic.py	2010-11-28 04:51:28 UTC (rev 6951)
+++ trunk/scipy/stats/mstats_basic.py	2010-11-28 04:52:01 UTC (rev 6952)
@@ -1787,45 +1787,52 @@

def plotting_positions(data, alpha=0.4, beta=0.4):
-    """Returns the plotting positions (or empirical percentile points) for the
-    data.
-    Plotting positions are defined as (i-alpha)/(n-alpha-beta), where:
+    """
+    Returns plotting positions (or empirical percentile points) for the data.
+
+    Plotting positions are defined as ``(i-alpha)/(n-alpha-beta)``, where:
- i is the rank order statistics
- n is the number of unmasked values along the given axis
- alpha and beta are two parameters.

Typical values for alpha and beta are:
-        - (0,1)    : *p(k) = k/n* : linear interpolation of cdf (R, type 4)
-        - (.5,.5)  : *p(k) = (k-1/2.)/n* : piecewise linear function (R, type 5)
-        - (0,0)    : *p(k) = k/(n+1)* : Weibull (R type 6)
-        - (1,1)    : *p(k) = (k-1)/(n-1)*. In this case, p(k) = mode[F(x[k])].
-          That's R default (R type 7)
-        - (1/3,1/3): *p(k) = (k-1/3)/(n+1/3)*. Then p(k) ~ median[F(x[k])].
+        - (0,1)    : ``p(k) = k/n``, linear interpolation of cdf (R, type 4)
+        - (.5,.5)  : ``p(k) = (k-1/2.)/n``, piecewise linear function
+                                           (R, type 5)
+        - (0,0)    : ``p(k) = k/(n+1)``, Weibull (R type 6)
+        - (1,1)    : ``p(k) = (k-1)/(n-1)``, in this case,
+                     ``p(k) = mode[F(x[k])]``. That's R default (R type 7)
+        - (1/3,1/3): ``p(k) = (k-1/3)/(n+1/3)``, then
+                     ``p(k) ~ median[F(x[k])]``.
The resulting quantile estimates are approximately median-unbiased
regardless of the distribution of x. (R type 8)
-        - (3/8,3/8): *p(k) = (k-3/8)/(n+1/4)*. Blom.
+        - (3/8,3/8): ``p(k) = (k-3/8)/(n+1/4)``, Blom.
The resulting quantile estimates are approximately unbiased
if x is normally distributed (R type 9)
- (.4,.4)  : approximately quantile unbiased (Cunnane)
- (.35,.35): APL, used with PWM

-Parameters
-----------
-    x : sequence
+    Parameters
+    ----------
+    data : array_like
Input data, as a sequence or array of dimension at most 2.
-    prob : sequence
-        List of quantiles to compute.
-    alpha : {0.4, float} optional
-        Plotting positions parameter.
-    beta : {0.4, float} optional
-        Plotting positions parameter.
+    alpha : float, optional
+        Plotting positions parameter. Default is 0.4.
+    beta : float, optional
+        Plotting positions parameter. Default is 0.4.

+    Returns
+    -------
+        The calculated plotting positions.
+
"""
data = ma.array(data, copy=False).reshape(1,-1)
n = data.count()
plpos = np.empty(data.size, dtype=float)
plpos[n:] = 0
-    plpos[data.argsort()[:n]] = (np.arange(1,n+1) - alpha)/(n+1-alpha-beta)
+    plpos[data.argsort()[:n]] = (np.arange(1, n+1) - alpha) / \
+                                (n + 1.0 - alpha - beta)

meppf = plotting_positions

Modified: trunk/scipy/stats/tests/test_mstats_basic.py
===================================================================
--- trunk/scipy/stats/tests/test_mstats_basic.py	2010-11-28 04:51:28 UTC (rev 6951)
+++ trunk/scipy/stats/tests/test_mstats_basic.py	2010-11-28 04:52:01 UTC (rev 6952)
@@ -15,25 +15,25 @@

class TestMquantiles(TestCase):
-    """Regression tests for mstats module."""
-    def test_mquantiles_limit_keyword(self):
-        """Ticket #867"""
-        data = np.array([[   6.,    7.,    1.],
-                         [  47.,   15.,    2.],
-                         [  49.,   36.,    3.],
-                         [  15.,   39.,    4.],
-                         [  42.,   40., -999.],
-                         [  41.,   41., -999.],
-                         [   7., -999., -999.],
-                         [  39., -999., -999.],
-                         [  43., -999., -999.],
-                         [  40., -999., -999.],
+    """Regression tests for mstats module."""
+    def test_mquantiles_limit_keyword(self):
+        """Ticket #867"""
+        data = np.array([[   6.,    7.,    1.],
+                         [  47.,   15.,    2.],
+                         [  49.,   36.,    3.],
+                         [  15.,   39.,    4.],
+                         [  42.,   40., -999.],
+                         [  41.,   41., -999.],
+                         [   7., -999., -999.],
+                         [  39., -999., -999.],
+                         [  43., -999., -999.],
+                         [  40., -999., -999.],
[  36., -999., -999.]])
-        desired = [[19.2, 14.6, 1.45],
-                   [40.0, 37.5, 2.5 ],
-                   [42.8, 40.05, 3.55]]
-        quants = mstats.mquantiles(data, axis=0, limit=(0, 50))
-        assert_almost_equal(quants, desired)
+        desired = [[19.2, 14.6, 1.45],
+                   [40.0, 37.5, 2.5 ],
+                   [42.8, 40.05, 3.55]]
+        quants = mstats.mquantiles(data, axis=0, limit=(0, 50))
+        assert_almost_equal(quants, desired)

@@ -528,5 +528,11 @@
assert_almost_equal(result[1], 0.5692, 4)

+def test_plotting_positions():
+    """Regression test for #1256"""
+    pos = mstats.plotting_positions(np.arange(3), 0, 0)
+    assert_array_almost_equal(pos.data, np.array([0.25, 0.5, 0.75]))
+
+
if __name__ == "__main__":
run_module_suite()

```