BitSize Python · Statistical Tests
A hundred tests. Five ideas. One map.
Every statistical test as one station on a map: when to use it, and when not.
How every test works
The null world built by shuffling, p-values as areas, α and tails, errors and power, effect sizes, the five engines and the multiple-testing tax.
- 01 Signal or noise? The test behind every teststats.permutation_test Up next
- 02 The p-value is an areastats.norm.sf · stats.t.sf Free account
- 03 α and the critical region: one tail or twostats.norm.ppf · stats.t.ppf · alternative= Free account
- 04 Two ways to be wrong: errors and powerTTestIndPower · solve_power 🔒 Subscribe
- 05 Surprise vs size: effect sizes and intervalsCohen’s d · ttest_ind(...).confidence_interval() 🔒 Subscribe
- 06 Reading the Atlas: five engines and the many-tests taxmultipletests (Bonferroni · Holm · BH) 🔒 Subscribe
One sample vs a value
z and t for a mean, one proportion, Poisson rates, a variance vs a target, sign and Wilcoxon tests, outliers.
- 07 z-test for a mean, when σ is knownstats.norm.sf · σ ÷ √n by hand 🔒 Subscribe
- 08 The one-sample t-teststats.ttest_1samp · confidence_interval() · alternative= 🔒 Subscribe
- 09 One proportion: exact binomial vs zstats.binomtest · proportion_ci() · the one-proportion z by hand 🔒 Subscribe
- 10 Counts per unit time: Poisson rate testsstats.poisson.cdf / sf · stats.poisson_means_test 🔒 Subscribe
- 11 A variance vs a target: the χ² variance teststats.chi2.sf · stats.chi2.cdf · stats.chi2.ppf 🔒 Subscribe
- 12 A median vs a value: sign and Wilcoxon testsstats.binomtest(k, n, 0.5) · stats.wilcoxon 🔒 Subscribe
- 13 Is that point an outlier? Grubbs and DixonGrubbs by hand (stats.t.ppf) · Dixon’s Q 🔒 Subscribe
Two groups
Two-sample z, Student and Welch t, paired t, two variances, Mann–Whitney, Mood, two proportions, permutation and bootstrap.
- 14 Two means, σ known: the two-sample zstats.norm.sf · ttest_ind(equal_var=False) 🔒 Subscribe
- 15 Student's pooled t-teststats.ttest_ind(equal_var=True) · f_oneway 🔒 Subscribe
- 16 Welch's t-test: the defaultstats.ttest_ind(equal_var=False) 🔒 Subscribe
- 17 Paired t: a one-sample t on the differencesstats.ttest_rel · ttest_1samp on the differences 🔒 Subscribe
- 18 Two variances: the F-test and Pitman–Morganstats.f.sf / f.cdf · stats.levene · pearsonr(x + y, x − y) 🔒 Subscribe
- 19 Mann–Whitney: comparing by ranksstats.mannwhitneyu 🔒 Subscribe
- 20 Mood's median teststats.median_test 🔒 Subscribe
- 21 Two proportions: z, χ² and Fisherstats.chi2_contingency · stats.fisher_exact 🔒 Subscribe
- 22 Permutation and bootstrap testsstats.permutation_test · stats.bootstrap 🔒 Subscribe
Many groups
ANOVA and Welch ANOVA, equal spreads, Tukey, Dunnett, contrasts and Scheffé, Kruskal–Wallis, Friedman and Cochran Q, Kendall’s W.
- 23 One-way ANOVA: why not many t-testsstats.f_oneway · MS between ÷ MS within 🔒 Subscribe
- 24 Welch's ANOVA, when spreads differanova_oneway(use_var='unequal') · stats.f_oneway 🔒 Subscribe
- 25 Equal spreads? Levene, Bartlett, Hartley, Cochranstats.levene · stats.bartlett · Fmax and C by hand 🔒 Subscribe
- 26 Which pairs differ? Tukey HSDTukey–Kramer by hand · qsturng (studentized range) 🔒 Subscribe
- 27 Everyone against a control: Dunnettstats.dunnett 🔒 Subscribe
- 28 Planned contrasts and Scheffécontrast t by hand · Scheffé (stats.f.ppf) 🔒 Subscribe
- 29 Is the top group really the best?Tukey–Kramer vs the top group (qsturng) 🔒 Subscribe
- 30 Kruskal–Wallis and Dunn's follow-upstats.kruskal · Dunn’s test by hand · multipletests 🔒 Subscribe
- 31 Repeated measures by ranks: Friedman and Cochran's Qstats.friedmanchisquare · cochrans_q 🔒 Subscribe
- 32 Do the judges agree? Kendall's WW by hand · stats.friedmanchisquare 🔒 Subscribe
Designs with structure
Two-way ANOVA, unequal cells, non-additivity, nested designs, random effects, Hotelling’s T².
- 33 Two-way ANOVA: main effects and interactionsmf.ols with * · sm.stats.anova_lm 🔒 Subscribe
- 34 Unequal cells: Type I, II and III sums of squaresanova_lm typ=1 · 2 · 3 · C(x, Sum) 🔒 Subscribe
- 35 Tukey's test for non-additivityTukey’s 1-df test by hand · stats.f.sf · np.log 🔒 Subscribe
- 36 Nested designsnested F-ratios by hand · stats.f.sf · f_oneway on class means 🔒 Subscribe
- 37 Random effects and variance componentsvariance components by hand · stats.f_oneway · stats.t.interval 🔒 Subscribe
- 38 Many outcomes at once: Hotelling's T²Hotelling’s T² by hand · np.cov · np.linalg.solve · stats.f.sf 🔒 Subscribe
Counts and tables
Goodness of fit, independence, Fisher’s exact test, homogeneity, the G-test, McNemar, trend tests, Mantel–Haenszel, transitions.
- 39 Goodness of fit for categoriesstats.chisquare · ddof · residuals (O − E)/√E 🔒 Subscribe
- 40 Independence in an r×c tablepd.crosstab · stats.chi2_contingency · stats.contingency.association 🔒 Subscribe
- 41 Small counts: Fisher's exact teststats.fisher_exact · stats.hypergeom · stats.barnard_exact · stats.boschloo_exact 🔒 Subscribe
- 42 Many groups, one mix? Homogeneitystats.chi2_contingency · pd.crosstab · residuals · Bonferroni pairs 🔒 Subscribe
- 43 The G-test: likelihood-ratio χ²stats.power_divergence · chi2_contingency(lambda_=) · partitioning G 🔒 Subscribe
- 44 Before and after, yes or no: McNemarstats.binomtest on the switchers · McNemar χ² · statsmodels mcnemar 🔒 Subscribe
- 45 Ordered groups: the Cochran–Armitage trend testCochran–Armitage by hand · stats.norm.sf · chi2_contingency · stats.pearsonr 🔒 Subscribe
- 46 Strata: Mantel–Haenszel and Simpson's paradoxStratifiedTable (statsmodels) · test_null_odds · oddsratio_pooled · chi2_contingency 🔒 Subscribe
- 47 Does what follows depend on what came before?pd.crosstab(x[:-1], x[1:]) · chi2_contingency · np.corrcoef 🔒 Subscribe
Relationships
Testing r, Fisher’s z, Spearman and Kendall, the slope test, lack of fit, multiple regression, Durbin–Watson, the linear-model view.
- 48 Is r zero? Testing a correlationstats.pearsonr · .confidence_interval() · t by hand with stats.t.sf 🔒 Subscribe
- 49 Comparing correlations: Fisher's zstats.pearsonr · np.arctanh / np.tanh · stats.norm.sf 🔒 Subscribe
- 50 Spearman and Kendall: correlation by ranksstats.spearmanr · stats.kendalltau (τ-b) · stats.pearsonr on .rank() 🔒 Subscribe
- 51 The slope test is the r teststats.linregress · stats.pearsonr · t = r√(n − 2)/√(1 − r²) 🔒 Subscribe
- 52 Is it really a line? Lack-of-fitsmf.ols('height ~ dose') vs smf.ols('height ~ C(dose)') · sm.stats.anova_lm 🔒 Subscribe
- 53 Many predictors: t per coefficient, F for the lotsmf.ols('price_k ~ size_m2 + rooms + age') · .pvalues · .fvalue · variance_inflation_factor · anova_lm 🔒 Subscribe
- 54 Autocorrelated errors: Durbin–Watsonstatsmodels durbin_watson · one Cochrane–Orcutt step · stats.linregress on differences 🔒 Subscribe
- 55 Everything is a linear modelsmf.ols with ~ 1, a 0/1 column, C(group) and a number · .pvalues · .f_pvalue 🔒 Subscribe
- 56 Wald, score and likelihood ratiosmf.logit · .pvalues (Wald) · .llf − .llnull (LR) · the score z by hand 🔒 Subscribe
Shape and fit
Shapiro–Wilk, Kolmogorov–Smirnov and Lilliefors, Anderson–Darling, two-sample and K-sample fit, choosing a model honestly.
- 57 Is it normal? Q–Q plots and Shapiro–Wilkstats.shapiro · stats.probplot · stats.skew 🔒 Subscribe
- 58 Kolmogorov–Smirnov and Lillieforsstats.kstest · statsmodels lilliefors 🔒 Subscribe
- 59 Anderson–Darling: watching the tailsstats.anderson · statsmodels lilliefors · stats.kurtosis 🔒 Subscribe
- 60 Two distributions: two-sample KSstats.ks_2samp · stats.mannwhitneyu · np.searchsorted 🔒 Subscribe
- 61 Several samples, one distribution?stats.anderson_ksamp · stats.kruskal · stats.ks_2samp 🔒 Subscribe
- 62 Choosing a model: testing the fit honestlyparametric bootstrap · stats.kstest · stats.goodness_of_fit 🔒 Subscribe
Randomness and order
Runs, turning points and trend, serial correlation, interleaved samples, which population made a series, streaks.
- 63 Runs: is this sequence random?runstest_1samp(x, cutoff='median') · np.median · stats.norm 🔒 Subscribe
- 64 Trend: Cox–Stuart and Mann–Kendallstats.kendalltau(np.arange(n), x) · stats.binomtest · np.triu_indices (Sen’s slope) 🔒 Subscribe
- 65 Serial correlation: von Neumann and Ljung–Boxacorr_ljungbox(x, lags=[10]) · acf(x, nlags=…) · np.diff (von Neumann ratio) 🔒 Subscribe
- 66 Two samples interleaved: Wald–Wolfowitzrunstest_2samp · np.sort · stats.norm.cdf · stats.mannwhitneyu 🔒 Subscribe
- 67 Which population made this series?stats.norm.logpdf · np.exp · posterior odds = likelihood ratio × prior odds 🔒 Subscribe
- 68 Streaks and the hot handrunstest_1samp · rng.permutation · a longest-streak statistic 🔒 Subscribe
Deciding between hypotheses
Neyman–Pearson, likelihood ratios, most powerful tests, sequential testing, peeking, equivalence and Bayes factors.
- 69 Simple vs simple: the Neyman–Pearson picturestats.norm.isf · stats.norm.sf · stats.norm.logpdf (the likelihood ratio) 🔒 Subscribe
- 70 Likelihood ratio testsstats.poisson.logpmf · stats.chi2.sf · stats.binomtest (the exact check) 🔒 Subscribe
- 71 Uniformly most powerful testsstats.norm.sf · stats.norm.isf · alternative= 🔒 Subscribe
- 72 Sequential testing: the SPRTnp.cumsum of log-likelihood steps · np.argmax for the first crossing 🔒 Subscribe
- 73 Peeking without a plantwo-proportion z at each look · np.cumsum · default_rng A/A simulation 🔒 Subscribe
- 74 Equivalence (TOST) and Bayes factorsttost_ind (statsmodels) · stats.ttest_ind(equal_var=False) · a BIC Bayes factor by hand 🔒 Subscribe
Circular data
Angles and times of day: the circular mean, the Rayleigh test, fit for angles, two or more circular samples.
- 75 Angles break the mean: the Rayleigh testnp.cos / np.sin · stats.circmean · Rayleigh Z = n·R̄² by hand 🔒 Subscribe
- 76 Fit for angles: Kuiper and WatsonKuiper V and Watson U² by hand · stats.kstest (for contrast) 🔒 Subscribe
- 77 Two circular samplesWatson–Williams by hand · stats.f.sf · stats.ttest_ind (for contrast) 🔒 Subscribe
- 78 Several circular groups: Watson–WilliamsWatson–Williams by hand · stats.f.sf 🔒 Subscribe
Case files
Real questions end to end: plan the route on the Atlas, run it, report it, and see what the tempting wrong test would have said.
- 79 Case file: did the redesign change basket sizes?stats.ttest_ind(equal_var=False) · stats.levene · stats.mannwhitneyu · stats.poisson_means_test 🔒 Subscribe
- 80 Case file: four clinics and a waiting listanova_oneway(use_var='unequal') · stats.ttest_ind(equal_var=False) · multipletests(method='holm') 🔒 Subscribe
- 81 Case file: survey tablesStratifiedTable (statsmodels) · stats.mannwhitneyu · Cochran–Armitage as √N·r · chi2_contingency 🔒 Subscribe
- 82 Case file: wind directions and sensor driftstats.circmean · Rayleigh by hand · stats.kendalltau with prewhitening · stats.ttest_1samp · Ljung–Box by hand 🔒 Subscribe