mixle.inference.nonparametric module¶
Classical nonparametric (rank-based) hypothesis tests.
Distribution-free two-sample, k-sample, paired, repeated-measures, ordered-alternative, and goodness-of-fit tests, each returning a small result object with the statistic, p-value, and – where standard – an effect size. Statistics are computed here (mid-ranks for ties); tail probabilities use the asymptotic reference distributions (normal / chi-square / Student-t / Kolmogorov) with the usual tie and continuity corrections, matching the conventions of SciPy / R.
- Two independent samples
mann_whitney_u()(Wilcoxon rank-sum),brunner_munzel(),
cliffs_delta(),ks_2samp()k independent samples :
kruskal_wallis(),mood_median_test(),dunn_test()(post-hoc) Paired / one sample :wilcoxon_signed_rank(),sign_test()Repeated measures :friedman_test()Ordered alternatives :jonckheere_terpstra()(independent),page_trend_test()(repeated) Goodness of fit / 1-samp:ks_1samp(),runs_test()
- class MannWhitneyResult(statistic: 'float', statistic2: 'float', zscore: 'float', pvalue: 'float', rank_biserial: 'float', alternative: 'str')[source]
Bases:
object- Parameters:
- statistic: float
- statistic2: float
- zscore: float
- pvalue: float
- rank_biserial: float
- alternative: str
- class WilcoxonResult(statistic: 'float', zscore: 'float', pvalue: 'float', rank_biserial: 'float', alternative: 'str')[source]
Bases:
object- statistic: float
- zscore: float
- pvalue: float
- rank_biserial: float
- alternative: str
- class DunnResult(comparisons, zscores, pvalues, p_adjust)[source]
Bases:
objectPost-hoc Dunn pairwise comparisons after Kruskal-Wallis.
- zscores: ndarray
- pvalues: ndarray
- p_adjust: str
- class TestResult(statistic, pvalue, extra=<factory>)[source]
Bases:
objectGeneric statistic + p-value result;
extracarries test-specific fields (effect size, df, …).- statistic: float
- pvalue: float
- mann_whitney_u(x, y, *, alternative='two-sided', use_continuity=True)[source]
Mann-Whitney U / Wilcoxon rank-sum test for two independent samples.
Tests whether
xis stochastically greater/less thany. Uses mid-ranks for ties, the tie-corrected normal approximation, and (default) a continuity correction.alternativeis'two-sided','greater'(x > y), or'less'. The rank-biserial correlation2*U1/(n1 n2) - 1is reported as the effect size.
- cliffs_delta(x, y)[source]
Cliff’s delta effect size in [-1, 1]:
P(x > y) - P(x < y)(rank-based, ties count as 0).
- brunner_munzel(x, y, *, alternative='two-sided', distribution='t')[source]
Brunner-Munzel test: the generalized Wilcoxon test that does NOT assume equal variances/shapes.
Tests the stochastic-equality null
P(x < y) + 0.5 P(x = y) = 1/2.distribution='t'uses a Satterthwaite t reference (recommended for small samples);'normal'the normal approximation. Reports the estimated relative effectp_hat = P(x < y) + 0.5 P(x = y)inextra.
- ks_2samp(x, y, *, alternative='two-sided')[source]
Two-sample Kolmogorov-Smirnov test: max gap between the two empirical CDFs (asymptotic p).
- ks_1samp(x, cdf, *, alternative='two-sided')[source]
One-sample Kolmogorov-Smirnov goodness-of-fit test against a fully-specified
cdfcallable.
- kruskal_wallis(*samples)[source]
Kruskal-Wallis H test: the rank-based k-sample generalization of Mann-Whitney (one-way ANOVA).
Tie-corrected H with a chi-square(k-1) reference.
extracarriesdfand theepsilon_squaredeffect size(H - k + 1)/(N - k).- Parameters:
samples (Any)
- Return type:
TestResult
- mood_median_test(*samples, ties='below')[source]
Mood’s median test: chi-square test that k samples share a common median.
Cross-tabulates each observation as above / (at-or-below) the pooled grand median and runs a chi-square test of independence on the resulting 2xk table.
extracarries thegrand_median.
- dunn_test(*samples, p_adjust='holm')[source]
Dunn’s post-hoc test: all pairwise rank-mean comparisons after a Kruskal-Wallis rejection.
Uses the pooled-rank z statistic with the shared tie-corrected variance, and adjusts the pairwise p-values by
'holm','bonferroni', or'none'.
- wilcoxon_signed_rank(x, y=None, *, alternative='two-sided', zero_method='wilcox', correction=False)[source]
Wilcoxon signed-rank test for paired samples (or one sample vs 0).
Ranks
|d|ford = x - y(mid-ranks for ties), splits into positive / negative rank sums, and uses the tie-corrected normal approximation.zero_method='wilcox'drops zero differences (and their ranks);'pratt'keeps them in the ranking but drops them from the sums. The matched-pairs rank-biserial correlation is reported as the effect size.
- sign_test(x, y=None, *, alternative='two-sided')[source]
Sign test for paired samples (or one sample vs 0): exact binomial test on the signs of
x - y.Only the directions of the differences are used (ties dropped), so it is maximally robust but less powerful than the signed-rank test.
extracarriesn_positiveandn(non-zero pairs).
- friedman_test(*measurements)[source]
Friedman test for k related samples (repeated measures): the rank-based repeated-measures ANOVA.
Pass each treatment as a separate equal-length array (one value per block). Ranks within each block, tie-corrects, and uses a chi-square(k-1) reference.
extracarriesdfand Kendall’sWconcordance effect size.- Parameters:
measurements (Any)
- Return type:
TestResult
- jonckheere_terpstra(*samples, alternative='increasing')[source]
Jonckheere-Terpstra test for an ORDERED alternative across independent samples.
More powerful than Kruskal-Wallis when the groups are expected to shift monotonically in the given order.
alternative='increasing'/'decreasing'/'two-sided'. Uses the tie-corrected normal approximation of the J statistic (sum of pairwise Mann-Whitney counts over ordered pairs).
- page_trend_test(*measurements, decreasing=False)[source]
Page’s trend test for an ORDERED alternative in repeated measures.
Like Friedman but for a pre-specified ordering of the k treatments (the columns, in order). Tests
L = sum_j j * R_jagainst the normal approximation. Setdecreasing=Trueto predict the reverse ordering.extracarries the z-score.
- runs_test(x, *, cutoff='median')[source]
Wald-Wolfowitz runs test for randomness of a binary/dichotomized sequence.
Dichotomizes
xabout its median (or a supplied numericcutoff) and tests whether the run count departs from what independence predicts (too few runs => clustering/trend; too many => over-alternation). Normal approximation, two-sided.extracarries the run count and z-score.