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 samplesmann_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

Parameters:
statistic: float
zscore: float
pvalue: float
rank_biserial: float
alternative: str
class DunnResult(comparisons, zscores, pvalues, p_adjust)[source]

Bases: object

Post-hoc Dunn pairwise comparisons after Kruskal-Wallis.

Parameters:
comparisons: list[tuple[int, int]]
zscores: ndarray
pvalues: ndarray
p_adjust: str
class TestResult(statistic, pvalue, extra=<factory>)[source]

Bases: object

Generic statistic + p-value result; extra carries test-specific fields (effect size, df, …).

Parameters:
statistic: float
pvalue: float
extra: dict[str, Any]
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 x is stochastically greater/less than y. Uses mid-ranks for ties, the tie-corrected normal approximation, and (default) a continuity correction. alternative is 'two-sided', 'greater' (x > y), or 'less'. The rank-biserial correlation 2*U1/(n1 n2) - 1 is reported as the effect size.

Parameters:
Return type:

MannWhitneyResult

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).

Parameters:
Return type:

float

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 effect p_hat = P(x < y) + 0.5 P(x = y) in extra.

Parameters:
Return type:

TestResult

ks_2samp(x, y, *, alternative='two-sided')[source]

Two-sample Kolmogorov-Smirnov test: max gap between the two empirical CDFs (asymptotic p).

Parameters:
Return type:

TestResult

ks_1samp(x, cdf, *, alternative='two-sided')[source]

One-sample Kolmogorov-Smirnov goodness-of-fit test against a fully-specified cdf callable.

Parameters:
Return type:

TestResult

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. extra carries df and the epsilon_squared effect 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. extra carries the grand_median.

Parameters:
Return type:

TestResult

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'.

Parameters:
  • samples (Any)

  • p_adjust (str)

Return type:

DunnResult

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| for d = 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.

Parameters:
Return type:

WilcoxonResult

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. extra carries n_positive and n (non-zero pairs).

Parameters:
Return type:

TestResult

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. extra carries df and Kendall’s W concordance 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).

Parameters:
  • samples (Any)

  • alternative (str)

Return type:

TestResult

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_j against the normal approximation. Set decreasing=True to predict the reverse ordering. extra carries the z-score.

Parameters:
  • measurements (Any)

  • decreasing (bool)

Return type:

TestResult

runs_test(x, *, cutoff='median')[source]

Wald-Wolfowitz runs test for randomness of a binary/dichotomized sequence.

Dichotomizes x about its median (or a supplied numeric cutoff) and tests whether the run count departs from what independence predicts (too few runs => clustering/trend; too many => over-alternation). Normal approximation, two-sided. extra carries the run count and z-score.

Parameters:
Return type:

TestResult