← Homepage

The Practitioner's Guide to Statistical Tests

October 17, 2026

Author: Daniel Jordan Viray

Ever stared at a dataset and wondered: z-test or t-test? ANOVA or Kruskal-Wallis? And what is a Wilcoxon signed-rank test, anyway? This guide is a method bank — every common test on one page: when to use it, a healthcare example with real output, the assumptions to check, the fallback test when those assumptions fail, and the Python code (click to expand).

Not sure which test? Answer three questions

Contents

The setup

Comparing means

Proportions & categories

When the assumptions break (rank tests)

The setup: null vs alternative, α, and tails

Every test on this page is the same argument. The null hypothesis (H0) says nothing is going on — no difference, no effect, the benchmark is right. The alternative hypothesis (HA) is the thing you're trying to show. You assume H0 is true, then ask: if it were, how surprising is my data? That surprise is the p-value: the probability of seeing data at least this extreme if H0 were true.

The significance level (α) is your surprise threshold, set before looking at the data — 0.05 is the convention. If p ≤ α, you reject H0; if p > α, you fail to reject it (more on that phrasing in the courtroom section — it matters).

Tails are where HA points. Two-tailed: a difference in either direction counts (the default — safest, and what you should use unless you committed in advance). Right-tailed: only "more than" counts. Left-tailed: only "less than" counts. Choosing the tail after seeing the data is cheating: it quietly doubles your false-alarm rate.

Three motivating examples — same machinery, three different questions:

Two-tailed — a new discharge process is rolled out; does length of stay change at all? Shorter stays might mean efficiency — or patients sent home too early. Longer might mean a bottleneck. You care about a change in either direction, so both tails carry evidence.

Null: the population mean length of stay is still 5.0 days (the process changed nothing).
Alternative: the population mean length of stay is not 5.0 days — it moved, one way or the other.

Right-tailed — does a new flu-vaccine formulation produce a stronger antibody response than the standard one? The only result that would change anyone's behavior is "stronger." Weaker or equal both mean the same decision: don't switch.

Null: the population mean antibody level with the new formulation is 40 units (no better than standard).
Alternative: the population mean antibody level is greater than 40 units.

Left-tailed — a care-management program was purchased for one reason: to cut cost. Does it? The contract decision is adopt-if-cheaper; a cost increase leads to the same "don't adopt" as no change, so only the left tail carries evidence.

Null: the population mean monthly cost per member is still $850 (the program saved nothing).
Alternative: the population mean monthly cost per member is less than $850.

z-scores & test statistics: one idea behind every test

A z-score locates a single observation: how many population standard deviations one value sits from the population mean. A fasting glucose of 136 in a population with mean 100 and a population standard deviation of 12 has a z-score of (136 − 100) / 12 = 3 — an unusual patient.

A z-statistic does the same job for a sample result: how many standard errors your sample mean sits from the null value. The yardstick changes — standard error, not standard deviation — because a mean of 64 patients wobbles far less than a single patient does. A sample mean of 104 against a null of 100, with a standard error of 1.5, gives a z-statistic of 2.7. Same shape of calculation, different job: the z-score locates a person; the z-statistic judges evidence. When people say "the z-test," they mean the z-statistic.

Every test statistic on this page — t, F, χ², U, H — is that same move with different plumbing: distance from H0, divided by how much wobble you'd expect by chance. Learn to read one and you can read them all. Field rule of thumb: a statistic around 2 standard errors from the null is roughly the p = 0.05 line for two-tailed tests.

Type I vs Type II errors

There are two ways to be wrong, and you can't minimize both at once:

You reject H0You fail to reject H0
H0 is trueType I error — a false alarm. Probability = α, which you set.Correct.
H0 is falseCorrect — this probability is the test's power (convention: aim for 80%).Type II error — a missed detection. Probability = β.

You control Type I directly (pick α). You control Type II only indirectly: a bigger sample or a bigger true effect separates the curves, and misses get rarer. Drag the sliders and watch β shrink:

The decision rule: guilty beyond a reasonable doubt

A hypothesis test is a criminal trial. The defendant is H0 — "no effect" — and the defendant is presumed innocent. The data is the evidence. Your α is the standard of proof: guilty beyond a reasonable doubt.

Reject H0 = a guilty verdict: the evidence is too strong to be a coincidence.

Fail to reject H0 = a "not guilty" verdict — which is not a declaration of innocence. It means the evidence wasn't strong enough. That's why statisticians never say "accept H0" or "we proved there's no effect": absence of evidence is not evidence of absence. Your study may simply have been too small to see what was there (that's β).

The two errors map too: a Type I error convicts an innocent defendant; a Type II error lets a guilty one walk. Tighten the standard of proof (smaller α) and you convict fewer innocents — but more of the guilty walk free. α = 0.05 is a convention for balancing the two, not a law of nature.

Comparing means

z-test (one sample, known population standard deviation)

Use it when: you're comparing a sample mean to a known benchmark and you genuinely know the population standard deviation — usually because a huge reference dataset or a calibrated instrument pinned it down.

Example: a reference lab has measured fasting glucose for years: population mean 100 mg/dL, population standard deviation 12, known from quality-control data. A new clinic's 64 patients average 103.7 mg/dL. Different population, or just noise? z = 2.44, p = 0.015 → reject H0 at a significance level of 0.05.

What we know, and what we don't. We know both population values the formula needs: the population mean under the null (100 — the benchmark) and the population standard deviation (12). Knowing the second one is the rare luxury, and it's the whole reason this test can use the exact normal distribution. What we don't know is whether the clinic's population mean has actually moved — that's what the sample is for.

Assumptions: the population standard deviation is truly known; independent observations; sample mean roughly normal (data normal, or n ≥ ~30).

Reality check: the population standard deviation is almost never known in real work — that's why the t-test below is the everyday tool. The z machinery's main modern jobs are proportions (further down) and large-sample approximations.

Data structure + Python code

Data: one sample summarized by its mean, plus the known population standard deviation. The course-style way — build the p-value by hand from the normal CDF:

import numpy as np
from scipy.stats import norm

xbar, mu0, sigma, n = 103.7, 100, 12, 64   # sample mean, H0 value, KNOWN sd, sample size
z = (xbar - mu0) / (sigma / np.sqrt(n))       # = 2.44
p = 2 * (1 - norm.cdf(abs(z)))                # two-tailed: double the upper tail
# left-tailed test:  p = norm.cdf(z)
# right-tailed test: p = 1 - norm.cdf(z)

Output: z = 2.44, p = 0.015.

One-sample t-test

Use it when: one sample mean vs a benchmark, and the population standard deviation is unknown — the normal real-world case.

Example: HbA1c for 25 patients at a diabetes clinic averages 7.54% against a target of 7.0%. T = 3.30, p = 0.003 → reject H0: the clinic's patients run above target.

What we know, and what we don't. We know the benchmark — the population mean under the null is 7.0% because that's the clinical target; it's handed to us, and it's what turns "our average looks high" into a testable question. We do not know the population standard deviation: how much HbA1c varies across all patients like these. Nobody has measured all of them — all we have is the sample standard deviation of our 25 patients, and that's an estimate of the true spread, not the true spread itself. With only 25 patients, the estimate itself wobbles.
How the t-test corrects for that: it swaps the normal distribution for the t distribution — the same bell shape, but with fatter tails. The fatter tails widen the "this could easily be chance" zone, charging you for the fact that one of your inputs (the spread) is itself a guess. The smaller the sample, the fatter the tails and the bigger the charge; as the sample grows, the spread estimate firms up, the tails slim down, and the t quietly becomes the z.

Assumptions: independent observations; data roughly normal, or n ≥ ~30 (the t-test tolerates mild skew at moderate n).

If that fails (small n, clearly skewed): the one-sample Wilcoxon signed-rank test against the benchmark value.

Data structure + Python code

Data: one column of numbers (here, a NumPy array of HbA1c values).

import pingouin as pg

# a1c: array of 25 HbA1c values, mean 7.54
pg.ttest(x=a1c, y=7.0)        # y = the benchmark value under H0

Key output: T = 3.30, dof = 24, p = 0.003.

Two-sample t-test

Use it when: comparing the means of two independent groups.

Example: length of stay under a new discharge protocol (35 patients, mean 4.1 days) vs standard care (35 patients, mean 5.5 days). T = -4.83, p < 0.001 → reject H0: the new protocol's stays are shorter.

What we know, and what we don't. There's no benchmark this time — we don't know either group's population mean; the gap between them is the question. We also don't know either population standard deviation, so both are estimated from the samples, and the t distribution charges us for estimating. (Welch's version lets the two spreads differ; the classic version pools them into one estimate.)

Assumptions: the two groups are independent; each group roughly normal or n ≥ ~30 per group. You do not need equal variances — use Welch's version (pingouin's default behavior), which adjusts for unequal spreads.

If that fails (heavy skew — and length of stay is famously skewed, so in real work you may land here directly): the Mann-Whitney U test.

Data structure + Python code

Data: two columns/arrays, one per group.

import pingouin as pg

pg.ttest(x=los_new, y=los_std)   # Welch's correction applied automatically

Key output: T = -4.83, p < 0.001.

Paired t-test

Use it when: the same subjects are measured twice — before/after, or matched pairs. The test runs on the differences, one per subject.

Example: systolic blood pressure in 20 patients before (mean 142 mmHg) and after (mean 136 mmHg) a 12-week hypertension program. T = -3.06, p = 0.006 → reject H0: blood pressure dropped.

What we know, and what we don't. No benchmark and no population values at all — what we have is each patient's pair of measurements, which collapses into one number per patient: their change. We don't know the population standard deviation of those changes, so it's estimated from the 20 differences — one estimate, one t charge. Pairing's gift is what it removes: the large patient-to-patient variation in baseline blood pressure never enters the spread at all.

Why pairing is powerful: each patient is their own control, so the large person-to-person variation cancels out of the comparison. Assumptions: the differences are roughly normal (not the raw values); pairs are independent of each other.

If that fails (differences skewed, or the outcome is ordinal): the Wilcoxon signed-rank test.

Data structure + Python code

Data: two aligned columns — row i is the same patient in both.

import pingouin as pg

pg.ttest(x=bp_after, y=bp_before, paired=True)

Key output: T = -3.06, dof = 19, p = 0.006.

ANOVA (one-way)

Use it when: comparing means across three or more groups with a single test. ANOVA answers only "does any group differ?" — not which ones.

Example: weight loss at 3 months across four programs — diet only (mean 2.3 kg), diet + exercise (3.8), medication (5.0), medication + exercise (7.6), 16 patients each. F = 30.1, p < 0.001 → reject H0: the programs are not all equal. Which ones differ is the next section's job.

What we know, and what we don't. We know the four sample means. We know none of the population means, and not the population standard deviation — everything in the F statistic is estimated from the data in front of us. F compares two of those estimates: the spread between the group means (the signal) against the spread of patients within each group (the noise). If the between-group spread dwarfs the within-group spread, the groups can't all share one population mean.

Assumptions: independent observations; roughly normal within each group (or decent n per group); roughly similar spreads across groups.

If that fails: the Kruskal-Wallis test.

Data structure + Python code

Data: a long-format table — one row per patient, a value column and a group column.

import pingouin as pg

# df: columns 'loss' (kg) and 'program' (4 labels), 64 rows
pg.anova(data=df, dv='loss', between='program')

Key output: F = 30.1, p < 0.001.

Pairwise comparisons + Bonferroni correction

Use it when: ANOVA says "something differs" and you need to know which pairs of groups differ.

The trap: four programs make 6 pairwise tests. Run each at α = 0.05 and the chance of at least one false alarm isn't 5% — it's about 26% (1 − 0.956). Every extra test is another lottery ticket for a fluke. Running many t-tests instead of ANOVA + corrected pairwise tests is exactly this mistake.

What we know, and what we don't. The knowledge situation is ANOVA's — every population value is estimated — plus one thing we know exactly: how many tests we're about to run (6). Bonferroni spends that knowledge: the more comparisons, the stricter each one's bar.

The Bonferroni fix: multiply each p-value by the number of tests (equivalently, judge each against α/6 ≈ 0.008). Simple, a bit conservative, and the right default. On the weight-loss data:

  Diet + exercise vs Diet only:  p = 0.014  ->  Bonferroni p = 0.083
  Diet + exercise vs Medication:  p = 0.070  ->  Bonferroni p = 0.418
  Diet + exercise vs Medication + exercise:  p = 0.000  ->  Bonferroni p = 0.000
  Diet only vs Medication:  p = 0.000  ->  Bonferroni p = 0.000
  Diet only vs Medication + exercise:  p = 0.000  ->  Bonferroni p = 0.000
  Medication vs Medication + exercise:  p = 0.000  ->  Bonferroni p = 0.001

The strongest gap (diet only vs medication + exercise) survives the correction easily; the correction costs you the borderline pairs — that's the price of honesty.

Data structure + Python code

Data: the same long-format table as ANOVA.

import pingouin as pg

pg.pairwise_tests(data=df, dv='loss', between='program', padjust='bonf')
# read the p_corr column: already Bonferroni-adjusted

Proportions & categories

One-sample proportion test

Use it when: one observed rate vs a published benchmark rate.

Example: 14 surgical-site infections in 200 surgeries (7.0%) vs a published benchmark of 5%. z = 1.11, p = 0.268 → fail to reject H0. Read that the courtroom way: not proof our rate is 5% — just not enough evidence to say it differs.

What we know, and what we don't. We know the benchmark rate (5%, published) and our own counts (14 infections out of 200 surgeries). We don't know our hospital's true underlying rate. But under the null, the rate is assumed to be 5% — and a rate carries its own spread — so even the standard error is fully determined by things we know. Nothing has to be estimated, so there's no t charge: plain z.

Why z here, not t? A proportion carries its own standard error: SE = √(p(1−p)/n). There's no separate spread to estimate from the sample the way a mean forces you to estimate the population standard deviation — and it's that estimating that earns the t distribution its fatter tails. With the SE coming from the proportion itself, the plain normal (z) is the right reference, once n is large enough for the normal approximation to the binomial.

Assumptions: independent cases; np and n(1−p) both ≥ ~10 under the benchmark p.

If n is too small: the exact binomial test (scipy.stats.binomtest) — same question, no normal approximation.

Data structure + Python code

Data: just two counts — how many events, out of how many trials.

from statsmodels.stats.proportion import proportions_ztest

proportions_ztest(count=14, nobs=200, value=0.05)   # value = benchmark under H0

Output: z = 1.11, p = 0.268.

Two-sample proportion test

Use it when: comparing a rate between two groups.

Example: 30-day readmissions: 15 of 150 patients (10%) on a new follow-up program vs 32 of 160 (20%) on standard care. z = -2.45, p = 0.014 → reject H0: the program's readmission rate is lower.

What we know, and what we don't. We know both samples' counts. We don't know either group's true rate, and there's no benchmark — each group is the other's reference. Under the null ("the two true rates are really the same"), the samples are pooled into one best estimate of that shared rate, and the pooled rate fixes the standard error. Once again nothing is left dangling to estimate, so it's z, not t.

Assumptions: independent groups; each cell count ≥ ~10. Worth knowing: this test is mathematically the same as a chi-squared test of independence on the 2×2 table — two doors into the same room.

Data structure + Python code

Data: two counts and two totals, as arrays.

import numpy as np
from statsmodels.stats.proportion import proportions_ztest

proportions_ztest(count=np.array([15, 32]), nobs=np.array([150, 160]))

Output: z = -2.45, p = 0.014.

Chi-squared test of independence

Use it when: two categorical variables, and you're asking whether they're associated. In one line: compare the counts you observed with the counts you'd expect if the variables were independent — big gaps make a big χ².

Example: smoking status vs COPD diagnosis in a screening sample of 500 people:

COPDNo COPDTotal
Smoker45 (26)155 (174)200
Non-smoker20 (39)280 (261)300
Total65435500

Observed counts — with the count expected if smoking and COPD were independent in parentheses. Expected counts come from the table's own totals: (row total × column total) / 500.

Read the COPD column: 45 smokers have COPD, where independence predicts only 26. That pile-up is the signal. χ² = 25.2, p < 0.001 → reject H0: smoking and COPD are associated. (Associated — not proven causal; that's a design question, not a test question.)

What we know, and what we don't. We know the observed counts — they're our data. We don't know whether the variables are associated. The expected counts aren't extra knowledge: they're computed from the table's own row and column totals — they're what the table would look like if independence were true. The test measures the distance between the table we got and the table independence predicts.

Assumptions: work with counts, never percentages; independent observations; the expected count is ≥ 5 in every cell (here the smallest expected count is 26).

If expected counts are too small (2×2 table): Fisher's exact test.

Data structure + Python code

Data: a long-format table — one row per person, one column per categorical variable.

import pingouin as pg

# df: 500 rows; columns 'smoker' (Smoker / Non-smoker) and 'copd' (COPD / No COPD)
expected, observed, stats = pg.chi2_independence(data=df, x='smoker', y='copd')

Key output (pearson row): χ² = 25.2, p < 0.001.

Chi-squared goodness-of-fit test

Use it when: one categorical variable, and you're asking whether observed counts match a hypothesized distribution.

Example: 1100 emergency-department arrivals across a week — Mon 205, Tue 160, Wed 150, Thu 152, Fri 158, Sat 135, Sun 140 — against a uniform expectation of ~157 per day. χ² = 20.1, p = 0.003 → reject H0: arrivals are not spread evenly; Mondays spike.

What we know, and what we don't. We know the observed counts, and we know the hypothesized distribution completely — "spread uniformly" hands us every expected count on a plate. We don't know whether reality follows it. That's the entire test: one fully specified prediction vs the counts that actually arrived.

Assumptions: counts, not proportions; expected count ≥ 5 in every category.

Data structure + Python code

Data: two aligned lists — observed counts and expected counts (same total).

from scipy.stats import chisquare

chisquare(f_obs=[205, 160, 150, 152, 158, 135, 140],
          f_exp=[157.1, 157.1, 157.1, 157.1, 157.1, 157.1, 157.1])

Output: χ² = 20.1, p = 0.003.

When the assumptions break: rank tests

The three tests below don't use the raw values at all — they convert everything to ranks (1st, 2nd, 3rd…) and test those. Skew and outliers can't bully a rank, and ordinal scores (pain 0–10, satisfaction 1–10) are welcome. The trade: slightly less power when the data really are normal. Each one is the fallback for a test above.

Wilcoxon signed-rank test

Use it when: paired data (before/after) whose differences are skewed — or an ordinal outcome. The paired t-test's fallback; a one-sample version also tests against a benchmark. In one line: rank the sizes of the differences, then check whether the positive and negative ranks balance.

Example: pain scores (0–10) before and after physical therapy for 14 back-pain patients — an ordinal scale, so ranks, not means. W = 0, p = 0.002 → reject H0: pain dropped. (W = 0 is as one-sided as it gets: every patient's pain went down.)

What we know, and what we don't. We know each patient's two scores. We assume nothing about any population mean or population standard deviation — pain scores are ordinal labels, so a "population standard deviation of pain" barely means anything. Giving up those unknowns is exactly why the test works on the ranks of the differences instead of the differences themselves.

Data structure + Python code

Data: two aligned arrays — row i is the same patient in both.

import pingouin as pg

pain_before = [8, 7, 9, 6, 8, 7, 9, 8, 6, 7, 8, 9, 7, 8]
pain_after  = [5, 6, 6, 5, 4, 7, 6, 5, 6, 4, 5, 7, 5, 6]
pg.wilcoxon(x=pain_before, y=pain_after)

Key output: W = 0, p = 0.002.

Mann-Whitney U test

Use it when: two independent groups and a skewed outcome or ordinal scores. The two-sample t-test's fallback. It asks whether a random patient from one group tends to rank above a random patient from the other — so report medians alongside it.

Example: wait times at two clinics (minutes, heavily right-skewed): median 32 at Clinic A vs 40 at Clinic B, 28 patients each. U = 266, p = 0.040 → reject H0: the waits genuinely differ.

What we know, and what we don't. We know the two samples of wait times. We don't assume a population mean or population standard deviation for either clinic — wait times are skewed, so those summaries would mislead anyway. The test trusts only the ordering: pool all 56 waits, rank them, and ask whether one clinic's ranks pile up at the slow end.

Data structure + Python code

Data: two arrays, one per group.

import pingouin as pg

pg.mwu(x=wait_a, y=wait_b)

Key output: U = 266, p = 0.040.

Kruskal-Wallis test

Use it when: three or more groups, skewed outcome or ordinal scores — ANOVA's fallback. (Same relationship as Mann-Whitney to the t-test: Kruskal-Wallis is to Wilcoxon-Mann-Whitney what ANOVA is to the t-test.)

Example: patient satisfaction (1–10) across four clinics, 18 patients each. H = 16.5, p < 0.001 → reject H0: the clinics differ. Follow up with pairwise Mann-Whitney tests plus a Bonferroni correction, exactly as in the pairwise section.

What we know, and what we don't. The same stance as Mann-Whitney, one dimension up: we know the four samples, assume no population means or population standard deviations, and compare the clinics purely on how their satisfaction ranks interleave.

Data structure + Python code

Data: a long-format table — one row per patient, score column + clinic column.

import pingouin as pg

# df: columns 'score' (1-10) and 'clinic' (A/B/C/D), 72 rows
pg.kruskal(data=df, dv='score', between='clinic')

Key output: H = 16.5, p < 0.001.

The one-table cheat sheet

TestUse it whenKey assumptionIf it fails, use
z-testMean vs benchmark, population standard deviation knownPopulation standard deviation known; n ≥ ~30— (that's the t-test)
One-sample tMean vs benchmarkRoughly normal, or n ≥ ~30Wilcoxon (vs the benchmark)
Two-sample tTwo group meansNormal-ish per group, or n ≥ ~30 eachMann-Whitney U
Paired tBefore/after meansDifferences roughly normalWilcoxon signed-rank
ANOVA3+ group meansNormal-ish per group, similar spreadsKruskal-Wallis
Pairwise + BonferroniAfter ANOVA: which pairs?Adjust p by the number of pairsPairwise rank tests + Bonferroni
One-sample proportionRate vs benchmarknp, n(1−p) ≥ ~10Exact binomial test
Two-sample proportionTwo group ratesCounts ≥ ~10 per cellFisher's exact / chi-squared
Chi-squared independenceTwo categorical variablesExpected ≥ 5 per cellFisher's exact (2×2)
Chi-squared goodness of fitCounts vs an expected distributionExpected ≥ 5 per categoryExact / simulated test
Wilcoxon signed-rankPaired, skewed or ordinalPaired differences exist— (it is the fallback)
Mann-Whitney UTwo groups, skewed or ordinalIndependent groups— (it is the fallback)
Kruskal-Wallis3+ groups, skewed or ordinalIndependent groups— (it is the fallback)
Prove it: pick any number on this page, open the dropdown under it, and run the code — the generator script already did, on the toy data described, and asserted every decision (reject / fail to reject) before writing a word of HTML. If a result hadn't matched the story, the page wouldn't exist.

Part of the Applied Data Science Lab. Companion: Statistical Significance, Visualized — the interactive p-value & power playground.