Skip to content

Commit

Permalink
DOC: add example for stats.mstats.compare_median_ms (scipy#14068)
Browse files Browse the repository at this point in the history
* Added example for compare_median_ms

Co-authored-by: Matt Haberland <[email protected]>
  • Loading branch information
sudosoph and mdhaber authored Feb 23, 2022
1 parent 4a856f1 commit 428b4e4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions scipy/stats/_mstats_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,30 @@ def compare_medians_ms(group_1, group_2, axis=None):
ndarray of floats with a length equal to the length of `group_1`
along `axis`.
Examples
--------
>>> from scipy import stats
>>> a = [1, 2, 3, 4, 5, 6, 7]
>>> b = [8, 9, 10, 11, 12, 13, 14]
>>> stats.mstats.compare_medians_ms(a, b, axis=None)
1.0693225866553746e-05
The function is vectorized to compute along a given axis.
>>> import numpy as np
>>> rng = np.random.default_rng()
>>> x = rng.random(size=(3, 7))
>>> y = rng.random(size=(3, 8))
>>> stats.mstats.compare_medians_ms(x, y, axis=1)
array([0.36908985, 0.36092538, 0.2765313 ])
References
----------
.. [1] McKean, Joseph W., and Ronald M. Schrader. "A comparison of methods
for studentizing the sample median." Communications in
Statistics-Simulation and Computation 13.6 (1984): 751-773.
"""
(med_1, med_2) = (ma.median(group_1,axis=axis), ma.median(group_2,axis=axis))
(std_1, std_2) = (mstats.stde_median(group_1, axis=axis),
Expand Down

0 comments on commit 428b4e4

Please sign in to comment.