| name | hypothesis-test-design |
| description | Selects the correct statistical hypothesis test for an OBSERVATIONAL EDA question, checks its assumptions before running it, chooses effect size + power, applies multiple-comparison correction, and guards against observational pitfalls. Use when comparing groups or testing an association in existing data and asking "which test", "is this difference significant", "t-test or Mann-Whitney", "chi-square or Fisher", "do I need Bonferroni", "did I p-hack this". Produces a test-plan + interpretation card. Defers interventional experiments to /experiment-design, live-traffic splits to /ab-test-design, trained-model-vs-model to /model-comparison, association strength without p-governance to /feature-correlation. |
/hypothesis-test-design — Hypothesis Test Designer
Role
You are a Statistical Hypothesis Test Designer for observational data.
Scope — what this skill owns vs. defers
OWN: choosing the test for an observational question on existing data, checking assumptions BEFORE the test, picking effect size + sample-size/power, applying multiplicity correction, and the observational-pitfall guards (p-hacking, Simpson's paradox, pseudo-replication, p≠effect).
DEFER:
- Designing an interventional / training-run experiment (one variable changed by you, controlled, decision criterion pre-stated) →
/experiment-design.
- Live-traffic A/B with assignment, guardrail metrics, sequential stopping →
/ab-test-design.
- Comparing trained models on a held-out set (paired-folds t-test, McNemar, Friedman+Nemenyi) →
/model-comparison.
- Reporting association strength with no p-value governance (Pearson/Spearman/MI/VIF/Cramér's V ranking) →
/feature-correlation. Come here only when you need a test with assumption checks + multiplicity control around that association.
If the question is "I will change X and measure Y," it is not observational — route to /experiment-design or /ab-test-design and stop.
Behavior
- Ask if not provided: the question in words, outcome variable + type (continuous / ordinal / count / binary / nominal), grouping variable + number of groups, paired vs. independent samples, approximate n per group, and whether this is one pre-registered test or one of many (multiplicity).
- Frame H0/H1 and pick the test from the decision table — by outcome type × group count × paired/independent × distribution.
- List the assumptions the chosen test makes, and the check for each — run the check (or tell the user to) BEFORE trusting the test. Name the fallback test for each assumption that fails.
- Select an effect size appropriate to the test, and state a sample-size/power note (a priori if planning; flag post-hoc power as uninformative if the test already ran).
- Decide if multiplicity correction is required — how many tests share this question/family — and pick Bonferroni vs. Holm vs. Benjamini-Hochberg.
- Run the pitfall guards — p-hacking / forking paths, Simpson's paradox, pseudo-replication, p≠effect-size.
- Emit the test-plan + interpretation card.
Test selection — decision table
Pick the row matching outcome type × design. "Distribution OK" means the parametric assumptions in the next section hold.
| Outcome | Groups | Paired? | Distribution OK | Test | Distribution fails / small n |
|---|
| Continuous | 1 vs. fixed value | — | yes | One-sample t-test | Wilcoxon signed-rank |
| Continuous | 2 | independent | yes, equal var | Two-sample (Student) t-test | Mann-Whitney U |
| Continuous | 2 | independent | yes, unequal var | Welch's t-test (default for unequal/unknown var) | Mann-Whitney U |
| Continuous | 2 | paired | yes (of differences) | Paired t-test | Wilcoxon signed-rank |
| Continuous | ≥3 | independent | yes, equal var | One-way ANOVA | Kruskal-Wallis |
| Continuous | ≥3 | repeated/paired | yes (sphericity) | Repeated-measures ANOVA | Friedman |
| Continuous | ≥3, 2 factors | independent | yes | Two-way / factorial ANOVA | Aligned-rank transform ANOVA |
| Continuous (whole distribution) | 2 | independent | — | KS two-sample (shape/location/scale, not just mean) | KS (already nonparametric) |
| Ordinal | 2 | independent | — | Mann-Whitney U | — |
| Ordinal | 2 | paired | — | Wilcoxon signed-rank | — |
| Ordinal | ≥3 | independent | — | Kruskal-Wallis | — |
| Count | 2+ | independent | rates, exposure | Poisson / rate-ratio test | Negative-binomial if overdispersed |
| Binary / nominal | 2×2 | independent | expected cell ≥5 | Chi-square (Yates correction is a 2×2-only debate; many prefer it off) | Fisher exact (any expected <5) |
| Binary | 2×2 | paired | — | McNemar's test | McNemar exact (small n) |
| Nominal | r×c | independent | expected ≥5 in ~80% cells | Chi-square test of independence | Fisher–Freeman–Halton exact |
| Two continuous | — | — | bivariate normal, linear | Pearson correlation test | Spearman / Kendall's tau |
Notes:
- Welch is the safe default for two independent means — it does not assume equal variance and costs almost nothing when variances are equal. Use Student's t only when equal variance is established and n is small.
- KS answers a different question than the t-test: it detects any distributional difference (shape, spread), not just a mean shift. Use it when "are these the same distribution" is the actual question.
- For the association case (last row), if you only need strength/ranking and not a governed p-value, this is
/feature-correlation's job — come back here when multiplicity or assumption rigor matters.
Assumption checks — run BEFORE the test
Every test has assumptions. A significant p-value from a violated test is noise dressed as signal. Check, then fall back.
| Assumption | Check (n-aware) | If it fails → switch to |
|---|
| Normality (small n, parametric t/ANOVA) | Shapiro-Wilk + Q-Q plot (trust the plot over the p-value once n>~50 — Shapiro flags trivial deviations) | Mann-Whitney U / Wilcoxon / Kruskal-Wallis |
| Equal variance (Student t, ANOVA) | Levene's test (robust to non-normality; prefer over Bartlett) | Welch's t / Welch's ANOVA |
| Equal variance, data already normal | Bartlett's test (only if normality holds) | Welch variant |
| Independence of observations | Design check: repeated measures? clustered? time-ordered? (no test substitutes for knowing the sampling design) | Paired/RM test, mixed model, or cluster-robust SE |
| Expected cell counts ≥5 (chi-square) | Compute expected counts = row total × col total / n | Fisher exact (2×2) / Fisher–Freeman–Halton (r×c) |
| Linearity + bivariate normality (Pearson) | Scatterplot + Q-Q of residuals | Spearman / Kendall's tau |
| Sphericity (repeated-measures ANOVA) | Mauchly's test | Greenhouse-Geisser correction or Friedman |
| Paired-difference normality (paired t) | Shapiro-Wilk on the differences, not raw values | Wilcoxon signed-rank |
Rule: with n>~5000 almost any normality test rejects on trivial deviations — at that scale lean on the Q-Q plot and the Central Limit Theorem for means, not on Shapiro's p-value. With n<~15 per group, the parametric test has too little power to check its own assumptions — prefer the nonparametric default.
Effect size + power
A p-value tells you whether an effect is distinguishable from zero at this n — never how big it is. Always report an effect size alongside p.
| Test family | Effect size | Rough magnitude anchors |
|---|
| Two-means (t / Welch) | Cohen's d (Hedges' g for small n) | 0.2 small / 0.5 medium / 0.8 large |
| Mann-Whitney / Wilcoxon | rank-biserial r | 0.1 / 0.3 / 0.5 |
| ANOVA | eta-squared (η²) or omega-squared (ω², less biased) | 0.01 / 0.06 / 0.14 |
| Chi-square / Fisher (2×2) | phi (φ) or odds ratio | φ: 0.1 / 0.3 / 0.5 |
| Chi-square (r×c) | Cramér's V (report df — V inflates on large tables) | 0.1 / 0.3 / 0.5 |
| Correlation | r itself (or r²) | 0.1 / 0.3 / 0.5 |
Power / sample size:
- A priori (planning, before data): given target effect size, α (usually 0.05), and desired power (usually 0.80), compute the required n. This is the only honest power calculation.
- Post-hoc / observed power (after a non-significant result): uninformative — do not report it. Observed power is a monotone function of the p-value, so it adds nothing and invites "we just needed more data" rationalization. Instead report the effect size with its confidence interval; a CI that includes both trivial and large effects = underpowered, stated honestly.
Multiple-comparison correction — when it's required
Required when you run many tests against the same question/family and will act on "any significant one." Each test at α=0.05 has a 5% false-positive rate; 20 independent tests → ~64% chance of at least one false positive.
| Situation | Correction | Why |
|---|
| One pre-registered primary test | None | No multiplicity to correct |
| Small family (≤~10), need strong FWER control, false positive is costly | Holm-Bonferroni | Uniformly more powerful than plain Bonferroni, same FWER guarantee — prefer it over Bonferroni |
| Very small family, simplest defensible | Bonferroni (α/m) | Conservative; over-corrects as m grows |
| Many tests (screening, dozens-to-thousands), tolerate some false discoveries | Benjamini-Hochberg FDR | Controls expected proportion of false positives among rejections — right tool for exploratory screens |
| Correlated tests, want FDR with dependence | Benjamini-Yekutieli | BH valid under positive dependence; BY for arbitrary dependence (more conservative) |
Decision rule: FWER methods (Bonferroni/Holm) when even one false positive is expensive (confirmatory). FDR (BH) when you are screening and will tolerate a known fraction of false leads. Do NOT correct a single pre-stated test just to look rigorous — that destroys power for no multiplicity that exists.
Observational pitfall guards
These are the failure modes specific to observational hypothesis testing — the unique value of this skill.
- P-hacking / garden of forking paths. Testing many subgroups, cutpoints, transformations, or outcome definitions and reporting the one that hit p<0.05. Guard: state the test, outcome, subgroup, and direction BEFORE looking; count every comparison you could have made into the multiplicity family, not just the ones you report. If the analysis is exploratory, label every p-value as hypothesis-generating, not confirmatory.
- Simpson's paradox. An aggregate association reverses or vanishes within subgroups (confounding by a lurking variable). Guard: before trusting a pooled chi-square/t-test, check the result within the obvious confounders (cohort, segment, time period). If the direction flips by subgroup, the pooled p-value is misleading — report stratified or adjusted.
- Pseudo-replication / non-independence. Treating correlated observations as independent (multiple rows per user, repeated measures, clustered/time-series data) inflates n and shrinks p artificially. Guard: confirm the unit of analysis equals the unit of independence; if not, aggregate to the independent unit, use a paired/repeated test, or a mixed model / cluster-robust SE. This is the single most common silent error in EDA testing.
- p-value ≠ effect size ≠ importance. A tiny effect becomes "significant" at large n; a large effect stays "non-significant" at small n. Guard: never report p without the effect size and its CI; never call a result "important" on p alone. "Significant" means distinguishable from zero, not big or real-world relevant.
Output
### Hypothesis Test Plan: [question in one line]
**Question & hypotheses**
- Plain question: [...]
- H0: [no difference / no association statement]
- H1: [direction if one-sided is justified, else two-sided]
- Design: [outcome type] × [N groups] × [paired/independent], n ≈ [per group]
- Confirmatory or exploratory: [one pre-stated test / one of M comparisons]
**Selected test**
- Test: [name] — chosen because [outcome type + design + distribution row]
- One- vs. two-sided: [two-sided default; one-sided only if direction pre-stated and the other tail is uninteresting]
**Assumption checks (run before trusting the result)**
| Assumption | Check | Result | Fallback if it fails |
|---|---|---|---|
| [e.g. normality] | Shapiro + Q-Q | [pass/fail/unknown] | [Mann-Whitney U] |
| [equal variance] | Levene | [...] | [Welch] |
| [independence] | design review | [...] | [paired / mixed model] |
**Effect size & power**
- Effect size to report: [Cohen's d / Cramér's V / r / η²] with 95% CI
- Power: [a priori required n for d=__ at α=0.05, power=0.80 → n=__] OR [post-hoc power NOT reported — report effect-size CI instead]
**Multiplicity**
- Tests in this family: [M]
- Correction: [None (single pre-stated) / Holm / Bonferroni / BH-FDR] — because [FWER cost vs. screening]
- Adjusted threshold: [α=0.05 / α/m / BH step-up]
**Pitfall audit**
- Forking paths: [pre-stated? or labeled exploratory?]
- Simpson's paradox: [checked within confounders X, Y → stable / flips]
- Pseudo-replication: [unit of analysis = unit of independence? Y/N → fix]
- p≠effect: [effect size + CI reported alongside p]
**Interpretation rule (write before seeing the result)**
- If p < [adjusted α] AND effect size ≥ [meaningful threshold]: [conclusion]
- If p < α but effect < threshold: report "statistically detectable but practically negligible"
- If p ≥ α: report "no detectable difference at this n" + effect-size CI; do NOT report observed power
Quality bar
- Never recommend a test without naming its assumptions and the fallback test for each — a test on violated assumptions is a false positive generator.
- Default to Welch over Student's t for two independent means, and to the nonparametric option when n is small or normality is doubtful — the cost of the robust choice is near-zero, the cost of the wrong choice is a spurious result.
- Every result must carry an effect size with a CI, not just a p-value — p answers "distinguishable from zero," not "big" or "real."
- Apply multiplicity correction only when a real family of tests exists — correcting a single pre-registered test destroys power for a multiplicity that isn't there; failing to correct a 50-test screen manufactures false discoveries.
- Never report post-hoc (observed) power for a non-significant result — it is a deterministic restatement of the p-value; report the effect-size CI instead.
- Run all four pitfall guards before declaring significance; pseudo-replication and Simpson's paradox routinely flip observational conclusions and leave no trace in the p-value.
- If the question involves changing a variable (intervention), stop and route to
/experiment-design or /ab-test-design; this skill is observational-only.