bundles / scipy latest / scipy / stats / _morestats / median_test
function
scipy.stats._morestats:median_test
source: /scipy/stats/_morestats.py :3961
Signature
def median_test ( * samples , ties = below , correction = True , lambda_ = 1 , nan_policy = propagate ) Summary
Perform a Mood's median test.
Extended Summary
Test that two or more samples come from populations with the same median.
Let n = len(samples) be the number of samples. The "grand median" of all the data is computed, and a contingency table is formed by classifying the values in each sample as being above or below the grand median. The contingency table, along with correction and lambda_, are passed to scipy.stats.chi2_contingency to compute the test statistic and p-value.
Parameters
sample1, sample2, ...: array_likeThe set of samples. There must be at least two samples. Each sample must be a one-dimensional sequence containing at least one value. The samples are not required to have the same length.
ties: str, optionalDetermines how values equal to the grand median are classified in the contingency table. The string must be one of
"below": Values equal to the grand median are counted as "below". "above": Values equal to the grand median are counted as "above". "ignore": Values equal to the grand median are not counted.
The default is "below".
correction: bool, optionalIf True, and there are just two samples, apply Yates' correction for continuity when computing the test statistic associated with the contingency table. Default is True.
lambda_: float or str, optionalBy default, the statistic computed in this test is Pearson's chi-squared statistic.
lambda_allows a statistic from the Cressie-Read power divergence family to be used instead. See power_divergence for details. Default is 1 (Pearson's chi-squared statistic).nan_policy: {'propagate', 'raise', 'omit'}, optionalDefines how to handle when input contains nan. 'propagate' returns nan, 'raise' throws an error, 'omit' performs the calculations ignoring nan values. Default is 'propagate'.
Returns
res: MedianTestResultAn object containing attributes:
statistic
statistic
pvalue
pvalue
median
median
table
table
Notes
Array API Standard Support
median_test has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ⛔ PyTorch ⛔ ⛔ JAX ⛔ ⛔ Dask ⛔ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
A biologist runs an experiment in which there are three groups of plants. Group 1 has 16 plants, group 2 has 15 plants, and group 3 has 17 plants. Each plant produces a number of seeds. The seed counts for each group are:: Group 1: 10 14 14 18 20 22 24 25 31 31 32 39 43 43 48 49 Group 2: 28 30 31 33 34 35 36 40 44 55 57 61 91 92 99 Group 3: 0 3 9 22 23 25 25 33 34 34 40 45 46 48 62 67 84 The following code applies Mood's median test to these samples.g1 = [10, 14, 14, 18, 20, 22, 24, 25, 31, 31, 32, 39, 43, 43, 48, 49] g2 = [28, 30, 31, 33, 34, 35, 36, 40, 44, 55, 57, 61, 91, 92, 99] g3 = [0, 3, 9, 22, 23, 25, 25, 33, 34, 34, 40, 45, 46, 48, 62, 67, 84] from scipy.stats import median_test res = median_test(g1, g2, g3)✓
res.median
✗res.table
✓res.pvalue
✗res = median_test(g1, g2, g3, lambda_="log-likelihood")
✓res.pvalue
✗res = median_test(g1, g2, g3, ties="above")
✓res.pvalue
✗res.table
✓See also
- kruskal
Compute the Kruskal-Wallis H-test for independent samples.
- mannwhitneyu
Computes the Mann-Whitney rank test on samples x and y.
Aliases
-
scipy.stats.median_test