Statistics and comparison brackets
Compute reporting rows with effect sizes and intervals, then attach the same results to a plot.
fp.stats holds the tests behind the plots. Every function returns a reporting row, a plain dict with the test, its statistic and p-value, the effect size and its 95 % confidence interval, so the same numbers can be written to a CSV in the plot’s _stats dissection and drawn as significance brackets over a meanmark or fluxbox. In the examples, the samples (sd_values, ctl, …) are arrays from your own analysis.
Two-group comparisons
Each two-group test takes two samples (a, b), orients signs as a − b, and returns one reporting row: a dict ready to save as a CSV in the plot’s _stats dissection.
import polars as pl
import fluxplot as fp
# sd_values and sleep_values are the two samples from your analysis.
row = fp.stats.welch_hedges(sd_values, sleep_values, names=("SD", "sleep"))
pl.DataFrame([row]).write_csv("plots/_dissections/app_gapdh/_stats/welch_ttest.csv")The tests are two-sided unless you pass alternative=. A row’s keys, in the order of fp.stats.REPORT_COLUMNS, are:
- Test and result:
sig_test_used,test_statistic_value,p-value,p_corrected_holm,dof. - Effect size:
effect_size_method,effect_size_value,effect_size_95_CI, and the interval as numbers ineffect_size_ci_lowandeffect_size_ci_high. - Samples:
n_a,n_b,n_total, andgroups(the names compared). - Also recorded:
alternative,p_corrected_bh,dof_error.
| Function | Design | Test |
|---|---|---|
welch_hedges |
independent samples, means | Welch’s t-test |
mann_whitney_cliff |
independent samples, ranks | Mann–Whitney U (the U of a) |
paired_t_hedges |
paired samples, mean difference | paired t-test |
wilcoxon_rank_biserial |
paired samples, ranks | Wilcoxon signed-rank (W+, zeros dropped) |
Each reports this effect size with a 95% confidence interval:
| Function | Effect size and 95% CI |
|---|---|
welch_hedges |
Hedges’ g with the non-pooled SD, sqrt((var_a + var_b) / 2); Bonett (2008) CI |
mann_whitney_cliff |
Cliff’s delta; Newcombe (2006) Method 5 score CI |
paired_t_hedges |
Hedges’ g_z (SD of the differences); exact noncentral-t CI |
wilcoxon_rank_biserial |
Kerby’s matched-pairs rank-biserial r; score CI |
The CIs target the population effect size, so they are never multiplied by Hedges’ J. Both rank-based CIs stay non-degenerate at complete separation (delta or r = ±1), which is common at n = 6. Rank tests report dof = None. fluxplot’s test suite (tests/test_stats.py) checks each test against SciPy and against the equation that defines its interval.
Multiple comparisons
A row on its own has p_corrected_holm == p-value (a family of one). Holm’s step-down correction needs every p-value in the family, so it is a separate pass over the rows of the comparisons that belong together (e.g. every measure tested on the same animals in one figure); extra keys such as a measure name ride along:
# sd and sleep map each measure name to its samples.
rows = [dict(measure=m, **fp.stats.welch_hedges(sd[m], sleep[m])) for m in measures]
# Fill p_corrected_holm across the family; the row order is kept.
rows = fp.stats.holm(rows)fp.stats.holm_adjusted(p) does the same for a bare array of p-values; fp.stats.bh(rows) / bh_adjusted(p) fill p_corrected_bh with Benjamini–Hochberg (false-discovery-rate) values for a screen of many measures. NaN p-values pass through both untouched.
Three or more groups
The omnibus tests return one row, in which groups lists every group and F tests carry dof and dof_error. The post-hoc tests return one row per pair. pairwise runs any two-group test above over the pairs of a {name: sample} family and corrects across them.
| Function | Test | Effect size and 95% CI |
|---|---|---|
anova_oneway |
one-way ANOVA | η² or ω² (effect="eta2" or "omega2"); Steiger’s noncentral-F CI |
welch_anova |
Welch’s ANOVA | ω²; noncentral-F CI on Welch’s dof |
kruskal_epsilon |
Kruskal–Wallis | ε² = H / (N − 1); seeded bootstrap CI |
rm_anova |
repeated-measures ANOVA | partial η²; noncentral-F CI |
friedman_kendall |
Friedman | Kendall’s W; seeded bootstrap CI |
tukey_hsd |
Tukey HSD | Hedges’ g, pooled SD |
games_howell |
Games–Howell | Hedges’ g, non-pooled SD; Bonett CI |
dunn |
Dunn’s test | Cliff’s delta; Newcombe CI |
pairwise |
any two-group test, per pair | the chosen test’s |
Notes on the tests:
rm_anovareports Greenhouse–Geisser-corrected degrees of freedom and p.tukey_hsdreports Tukey’s family-wise p as it is, without a further correction.games_howelluses the studentized range on Welch’s degrees of freedom.dunnis Dunn’s rank-sum test after Kruskal–Wallis, corrected withadjust="holm"by default.pairwisecorrects across the pairs withadjust="holm"(the default) or"bh".
The group-based functions take the samples as positional arguments with optional names=, for example fp.stats.welch_anova(ctl, drug, sham, names=("ctl", "drug", "sham")). The repeated-measures functions take a long table and its column names: fp.stats.rm_anova(table, subject, within, dv). Exact signatures are in the API reference. fluxplot’s test suite (tests/test_stats_multi.py) checks them against pingouin and scikit-posthocs reference values.
Draw the comparisons
fp.brackets(ax, rows, positions=…) draws one significance bracket per post-hoc row and stacks them automatically: shortest span first, each bracket one step above the data it spans and above every bracket it overlaps in x (multiplicative steps on a log axis), so nothing crosses. positions maps group name → x; a meanmark or fluxbox result provides it as .positions, and gb.brackets(rows) is the one-liner:
# ctl, drug and sham are the samples; df["group"] holds the same three names.
rows = fp.stats.pairwise(fp.stats.welch_hedges,
{"ctl": ctl, "drug": drug, "sham": sham})
gb = fp.meanmark(data=df, x="group", y="value", ax=ax)
# Stars (***, **, *, ns) from p_corrected_holm:
gb.brackets(rows)
# Or "p = 0.003" labels from the BH-corrected p-values, without the ns pairs:
gb.brackets(rows, label="p", ns=False, p_column="p_corrected_bh")label is "stars", "p", "both" or a callable on the row. thresholds, top, step and tip shape the stack, and extra keywords are passed to fp.significance_bracket. Without a result object, fp.brackets(ax, rows) reads the positions from the x tick labels, which must name every group. Brackets need a vertical plot: a horizontal meanmark (orientation="horizontal") raises. Each bracket’s manifest overlay carries between: [a, b], p and a stats block — test, statistic, raw and corrected p, correction, effect size and its CI, sizes — so the figure states exactly which test each star came from, and flux get-plot-data reports it.
fp.stats.pairwise become stacked brackets with mm.brackets(rows); stars follow the Holm-corrected p. Synthetic values.
References
fluxplot’s statistics build on SciPy. The tests, effect sizes, intervals and corrections follow these papers; cite the ones your figure relies on.
- Benjamini, Y. and Hochberg, Y. (1995). Controlling the false discovery rate: a practical and powerful approach to multiple testing. Journal of the Royal Statistical Society B 57, 289–300. doi:10.1111/j.2517-6161.1995.tb02031.x
- Bonett, D. G. (2008). Confidence intervals for standardized linear contrasts of means. Psychological Methods 13, 99–109. doi:10.1037/1082-989X.13.2.99
- Cliff, N. (1996). Ordinal Methods for Behavioral Data Analysis. Lawrence Erlbaum.
- Dunn, O. J. (1964). Multiple comparisons using rank sums. Technometrics 6, 241–252. doi:10.1080/00401706.1964.10490181
- Friedman, M. (1937). The use of ranks to avoid the assumption of normality implicit in the analysis of variance. Journal of the American Statistical Association 32, 675–701. doi:10.1080/01621459.1937.10503522
- Games, P. A. and Howell, J. F. (1976). Pairwise multiple comparison procedures with unequal n’s and/or variances: a Monte Carlo study. Journal of Educational Statistics 1, 113–125.
- Hedges, L. V. (1981). Distribution theory for Glass’s estimator of effect size and related estimators. Journal of Educational Statistics 6, 107–128. doi:10.3102/10769986006002107
- Holm, S. (1979). A simple sequentially rejective multiple test procedure. Scandinavian Journal of Statistics 6, 65–70.
- Kerby, D. S. (2014). The simple difference formula: an approach to teaching nonparametric correlation. Comprehensive Psychology 3, 11.IT.3.1. doi:10.2466/11.IT.3.1
- Kruskal, W. H. and Wallis, W. A. (1952). Use of ranks in one-criterion variance analysis. Journal of the American Statistical Association 47, 583–621. doi:10.1080/01621459.1952.10483441
- Mann, H. B. and Whitney, D. R. (1947). On a test of whether one of two random variables is stochastically larger than the other. Annals of Mathematical Statistics 18, 50–60. doi:10.1214/aoms/1177730491
- Newcombe, R. G. (2006). Confidence intervals for an effect size measure based on the Mann–Whitney statistic. Part 2: asymptotic methods and evaluation. Statistics in Medicine 25, 559–573. doi:10.1002/sim.2324
- Steiger, J. H. (2004). Beyond the F test: effect size confidence intervals and tests of close fit in the analysis of variance and contrast analysis. Psychological Methods 9, 164–182. doi:10.1037/1082-989X.9.2.164
- Tukey, J. W. (1949). Comparing individual means in the analysis of variance. Biometrics 5, 99–114.
- Welch, B. L. (1947). The generalization of ‘Student’s’ problem when several different population variances are involved. Biometrika 34, 28–35. doi:10.1093/biomet/34.1-2.28
- Welch, B. L. (1951). On the comparison of several mean values: an alternative approach. Biometrika 38, 330–336. doi:10.1093/biomet/38.3-4.330
- Wilcoxon, F. (1945). Individual comparisons by ranking methods. Biometrics Bulletin 1, 80–83. doi:10.2307/3001968