All available hypothesis tests
Means and group comparisons
Proportions, A/B testing and 2×2 tables
Variances, correlation and association
Goodness of fit and normality
Statistical power
What is a hypothesis test?
A hypothesis test (also called a statistical test) is a formal procedure that lets you decide, from sample data, whether the empirical evidence is strong enough to reject a starting claim about the population. The core idea is simple: we state two competing hypotheses and use the data to see which one is more compatible with reality.
This kind of reasoning shows up across many fields: medicine (is this drug more effective than a placebo?), engineering (has the new production process improved?), marketing (which of two page versions converts better?), or social science (do scores differ between two groups?). In every case, the logical scheme is the same.
The logic of a test: statistical proof by contradiction
The mechanism works much like a proof by contradiction. You start from a reference hypothesis — the null hypothesis (H₀) — which represents the scenario you want to challenge: "there is no effect," "there is no difference," "the parameter equals exactly μ₀." You then work out what data you would expect to see if H₀ were true. If the observed data are very unlikely under that scenario, you conclude that H₀ is implausible and reject it in favor of the alternative hypothesis (H₁).
It's crucial to understand that a hypothesis test never "proves" anything with absolute certainty. What it does is quantify the compatibility between the data and H₀, and then, using a probability threshold (the significance level α), make an operational decision.
The hypotheses: null and alternative
Null hypothesis (H₀)
The null hypothesis is the conservative starting point. It usually states that there is no effect, that the means are equal, or that a parameter takes a specific value. It is always written with an equality (=, ≤ or ≥, depending on the type of test). Examples:
- H₀: μ = 50 (the population mean is 50)
- H₀: μ₁ = μ₂ (the two means are equal)
- H₀: p = 0.30 (the proportion is 30%)
- H₀: σ₁² = σ₂² (the variances are equal)
Alternative hypothesis (H₁ or Hₐ)
The alternative hypothesis expresses what you suspect or want to demonstrate: that there is an effect, a difference, or a change in a particular direction. It comes in three variants, depending on the type of test:
- Two-sided (two-tailed): H₁: μ ≠ μ₀ — rejected whether the statistic is very high or very low.
- Right-tailed (upper tail): H₁: μ > μ₀ — rejected only if the statistic falls in the upper tail.
- Left-tailed (lower tail): H₁: μ < μ₀ — rejected only if the statistic falls in the lower tail.
The choice between two-sided and one-sided must be made before looking at the data, based on the research question. Choosing the type of test after seeing the data artificially inflates the false-positive rate.
The test statistic and the p-value
Test statistic
The test statistic is a number computed from the sample that summarizes the evidence against H₀. Its exact distribution under H₀ is known mathematically, which lets you compute probabilities. The most common ones are:
- z: used when the population variance is known or the sample size is large (roughly n ≥ 30). It follows a standard normal distribution N(0, 1) under H₀.
- Student's t: used when the population variance is unknown and estimated from the sample. It follows a t distribution with n − 1 degrees of freedom.
- Snedecor's F: used when comparing variances or in ANOVA, where variances are compared across groups.
- χ² (chi-square): used in contingency tables and goodness-of-fit tests.
The p-value
The p-value is the probability of obtaining a statistic as extreme as, or more extreme than, the one observed, assuming H₀ is true. Formally:
- Two-sided test: p = P(|T| ≥ |t_obs| | H₀)
- Right tail: p = P(T ≥ t_obs | H₀)
- Left tail: p = P(T ≤ t_obs | H₀)
A small p-value indicates that the observed data would be very unlikely if H₀ were true, so there is evidence against H₀. The decision is made by comparing the p-value with the significance level α, set in advance:
- If p-value < α → reject H₀.
- If p-value ≥ α → do not reject H₀ (it is not "accepted" — there simply isn't enough evidence to reject it).
What the p-value is not
The p-value is one of the most misunderstood concepts in statistics. It's important to be clear about what it does not mean:
- It is not the probability that H₀ is true.
- It is not the probability that you made an error.
- It does not indicate the size or the practical importance of the effect.
- A p-value of 0.049 is not "almost significant"; 0.051 is not "almost not significant." The α threshold is an operational convention, not a boundary of knowledge.
Type I and Type II errors
Whenever you make a statistical decision there is always a chance of being wrong. There are two distinct kinds of error, and there's a fundamental tension between them:
Type I error (α) — False positive
Rejecting H₀ when it is actually true. This is the error of "seeing an effect that doesn't exist." Its probability is exactly α (the chosen significance level). If we set α = 0.05, on average 5% of tests performed when H₀ is true will produce a false positive.
Type II error (β) — False negative
Failing to reject H₀ when it is actually false. This is the error of "not seeing an effect that does exist." Its probability is β, and it depends on the sample size, the size of the real effect, and the α level. It is controlled through study design.
Statistical power (1 − β)
The probability of detecting a real effect when it actually exists. A study with 80% power will fail to detect the effect 20% of the time even when that effect is real. Studies are typically designed to have power ≥ 0.80.
The relationship between α and β is inverse, all else being equal: lowering α (being stricter about rejecting H₀) increases β (makes it harder to detect real effects). The only way to reduce both at once is to increase the sample size.
| H₀ true | H₀ false | |
|---|---|---|
| Do not reject H₀ | Correct decision (prob. = 1 − α) | Type II error (prob. = β) |
| Reject H₀ | Type I error (prob. = α) | Correct decision · Power (1 − β) |
Statistical power: what it is and what it depends on
Power answers the question: "if the effect I suspect really exists, how likely is my study to detect it?" It's one of the most important criteria in study design, even though in practice it often gets overlooked.
Statistical power (1 − β) depends on four interacting factors:
- Sample size (n): the factor with the greatest practical impact. As n grows, the standard error shrinks, confidence intervals narrow, and the distribution of the statistic under H₁ moves further from the distribution under H₀, making detection easier.
- Effect size (d, f, w…): the larger the real difference between the parameter under H₁ and the value under H₀, the easier it is to detect. If the real effect is very small, a much larger sample is needed to achieve adequate power.
- Variability of the data (σ): greater spread "masks" the signal. With more homogeneous data, the same difference is easier to detect.
- Significance level (α): raising α (for example from 0.01 to 0.05) widens the rejection region and increases power, but at the cost of admitting more false positives.
An a priori power analysis — carried out before collecting data — lets you determine the sample size needed to reach a target power (typically 0.80 or 0.90) given a minimum effect size of interest. Doing this is essential practice in rigorous scientific studies.
Effect size: beyond the p-value
Statistically significant is not the same as practically important. This confusion is one of the most serious and common mistakes in applied statistics.
With a very large sample, a difference of 0.1 points between two groups can produce p < 0.001, even though it has no practical relevance whatsoever. Conversely, with small samples, a clinically relevant difference may fail to reach statistical significance.
Effect size indices quantify the magnitude of a difference in standardized units, independent of sample size:
- Cohen's d (difference of two means): d = (μ₁ − μ₂) / σ_pooled. Rough guidelines: small ≈ 0.2; medium ≈ 0.5; large ≈ 0.8.
- Pearson's r (correlation or ANOVA): r = 0.1 (small), 0.3 (medium), 0.5 (large).
- η² and partial η² (ANOVA): proportion of variance explained by the factor.
- Cohen's w (chi-square): w = 0.1 (small), 0.3 (medium), 0.5 (large).
- Relative risk, odds ratio (proportions): indicate how many times more likely the event is in one group relative to the other.
Current best practice recommends always reporting, alongside the p-value:
- The point estimate of the effect (difference of means, difference of proportions, odds ratio…).
- The confidence interval of the effect (typically at 95%).
- A standardized effect size index.
- An assessment of practical relevance in the context of the problem.
Steps to carry out a hypothesis test
Regardless of the type of test, the procedure always follows the same scheme:
- State the hypotheses: formulate H₀ and H₁ based on the research question, and decide whether the test is two-sided or one-sided.
- Set the significance level (α): typically 0.05, though stricter contexts use 0.01. It must be set before collecting data.
- Check the test's assumptions: normality, independence of observations, homogeneity of variances, minimum expected frequencies, etc.
- Choose the appropriate statistic: z, t, F, χ²… depending on the type of variable, the number of groups, and the assumptions verified.
- Compute the statistic and the p-value from the sample data.
- Make the decision: if p-value < α, reject H₀; if p-value ≥ α, do not reject H₀.
- Compute the effect size and interpret the results in context.
- Report the results: include the statistic, degrees of freedom, p-value, estimated effect, and confidence interval.
Common assumptions and how to check them
Every test rests on a set of assumptions that must hold (at least approximately) for the inference to be valid. Ignoring the assumptions is one of the most common sources of misleading results.
Normality
Parametric tests (t, z, F) assume that the data come from a normal distribution or, thanks to the Central Limit Theorem, that the sample size is large enough for the statistic to converge to the theoretical distribution. For n ≥ 30 the CLT is usually sufficient; with small samples it's worth checking normality with the Shapiro-Wilk test or the Kolmogorov-Smirnov test.
Independence of observations
Observations must be independent of one another. The most frequent violation occurs when there are repeated measures on the same subject (before/after) or when the data are clustered. In these cases you should use a paired-sample test or mixed models.
Homogeneity of variances (homoscedasticity)
The two-independent-samples t-test and ANOVA assume the group variances are equal. This can be checked with Levene's test. If it doesn't hold, robust alternatives exist, such as Welch's test for two means.
Minimum expected frequencies (chi-square)
In contingency tables, each cell should have an expected frequency of at least 5 (some sources say 1, provided no more than 20% of cells fall below 5). If this doesn't hold, use Fisher's exact test.
Which hypothesis test should I use: a selection guide
The choice of test depends on three main factors: the type of variable, the number of groups or samples, and whether the samples are independent or paired.
Numerical variable — 1 group
One-mean test: compares the sample mean with a hypothesized value μ₀. Use z if σ is known, or t if σ is unknown.
Numerical variable — 2 independent groups
Two-means test: compares the means of two distinct groups. Uses Welch's t (unequal variances) or pooled Student's t (equal variances).
Numerical variable — 2 paired groups
Paired-means test: used when each observation in one group is matched with one in the other (before/after, twins…). Computed on the differences d̄.
Numerical variable — ≥ 3 groups
One-way ANOVA calculator: tests whether at least one mean differs from the rest. If ANOVA is significant, multiple post hoc comparisons follow.
Categorical variable — 1 group
One-proportion test: compares the sample proportion with a hypothesized value p₀. Use z for large n, or the exact binomial test for small n.
Categorical variable — 2 independent groups
Two-proportions test: tests whether the proportions of two groups are equal. Alternative: Fisher's test for small samples.
Contingency table (independence)
Chi-square test of independence calculator: tests whether two categorical variables are independent. For 2×2 tables with low frequencies, use Fisher's test.
Goodness of fit
Chi-square goodness-of-fit calculator: tests whether an empirical distribution fits a theoretical distribution. For continuous distributions, use Kolmogorov-Smirnov.
Comparing variances
Variance test: uses the F statistic to compare two population variances. It is sensitive to non-normality.
Checking normality
Shapiro-Wilk (preferred for n < 50) or Kolmogorov-Smirnov (valid for large samples). These are preliminary tests, not the main test.
Worked example 1: one-mean test (t-test)
Problem: A manufacturer claims that the average weight of its packages is 500 g. A sample of n = 25 packages is taken, giving a sample mean of x̄ = 493 g and a sample standard deviation of s = 15 g. Is there enough evidence to conclude that the mean weight differs from 500 g, at α = 0.05?
Step 1 — Hypotheses:
H₀: μ = 500 g
H₁: μ ≠ 500 g (two-sided test)
Step 2 — Significance level: α = 0.05.
Step 3 — Check assumptions: random sample, σ unknown → t-test with n − 1 = 24 degrees of freedom.
Step 4 — Test statistic:
t = (x̄ − μ₀) / (s / √n) = (493 − 500) / (15 / √25) = −7 / 3 = −2.333
Step 5 — P-value: for t = −2.333 with 24 degrees of freedom and a two-sided test, p-value ≈ 0.028.
Step 6 — Decision: p-value (0.028) < α (0.05) → reject H₀. There is enough statistical evidence to conclude that the mean weight differs from 500 g.
Step 7 — Effect size: Cohen's d = (x̄ − μ₀) / s = 7 / 15 ≈ 0.47 (a medium-moderate effect). The 95% confidence interval for μ would be approximately (486.8 g, 499.2 g).
You can verify this result with the one-mean test calculator.
Worked example 2: two-proportion test
Problem: A company launches a new landing page (variant B) against the current one (variant A). In variant A, 420 out of 10,000 visitors make a purchase. In variant B, 480 out of 10,000 visitors purchase. Is there evidence that the conversion rate differs between the two variants? α = 0.05.
Hypotheses:
H₀: p_A = p_B (the conversion rates are equal)
H₁: p_A ≠ p_B (two-sided)
Sample proportions:
p̂_A = 420 / 10,000 = 0.042 (4.2%)
p̂_B = 480 / 10,000 = 0.048 (4.8%)
Pooled proportion under H₀:
p̂ = (420 + 480) / (10,000 + 10,000) = 900 / 20,000 = 0.045
z statistic:
z = (p̂_A − p̂_B) / √[p̂(1 − p̂)(1/n_A + 1/n_B)]
z = (0.042 − 0.048) / √[0.045 × 0.955 × (1/10,000 + 1/10,000)]
z = −0.006 / √[0.045 × 0.955 × 0.0002]
z = −0.006 / √[0.00000859] ≈ −0.006 / 0.002931 ≈ −2.047
P-value (two-sided): p ≈ 0.041.
Decision: p (0.041) < α (0.05) → reject H₀. The 0.6-percentage-point difference is statistically significant. However, the effect size is very small (w ≈ 0.02), so it's worth assessing whether a ~14% relative lift in conversion has real economic relevance before acting on it.
Try it with the two-proportions calculator.
Worked example 3: chi-square test of independence
Problem: We want to know whether gender is associated with a preference for three types of music (pop, rock, electronic). 300 people are surveyed, giving the following table:
| Pop | Rock | Electronic | Total | |
|---|---|---|---|---|
| Men | 50 | 70 | 30 | 150 |
| Women | 80 | 40 | 30 | 150 |
| Total | 130 | 110 | 60 | 300 |
Hypotheses:
H₀: gender and music preference are independent
H₁: gender and music preference are associated
χ² statistic = Σ [(O − E)² / E], where E = (row total × column total) / n.
Computing the expected frequencies and the statistic: χ² ≈ 15.10 with (2 − 1)(3 − 1) = 2 degrees of freedom.
P-value ≈ 0.0005 < 0.05 → reject H₀. Gender is significantly associated with music preference. The effect size (Cramér's V ≈ 0.22) indicates a moderate association.
Calculate your own with the chi-square test of independence calculator.
Common mistakes and myths about hypothesis testing
1. "p < 0.05 means there's a real effect"
A small p-value only indicates that the data are unlikely under H₀. It doesn't guarantee the effect is real or reproducible. With many simultaneous comparisons (the multiple-comparisons problem), obtaining p < 0.05 by pure chance is to be expected.
2. "p = 0.06 isn't significant, so there's no effect"
Absence of statistical significance is not evidence of absence of an effect. It can simply reflect an insufficient sample. Reporting only whether the 0.05 threshold was crossed is poor practice that discards valuable information.
3. "The p-value is the probability that H₀ is true"
The p-value is P(data as extreme or more | H₀ true), not P(H₀ true | data). Getting probabilities about hypotheses requires a Bayesian approach with a prior distribution.
4. "With a large n you always get significance"
True, and that's exactly the problem. With n = 1,000,000, an irrelevant difference of 0.001 units can have p < 0.001. That's why effect size and confidence intervals are indispensable.
5. "If the test doesn't meet its assumptions, the results are useless"
It depends on how severe the violation is. Many tests are robust to moderate departures from normality, especially with large n. In severe cases, non-parametric alternatives or data transformations exist.
6. "A hypothesis test is enough to make a decision"
A test is a tool, not an oracle. Decisions should integrate context, costs, the effect size, and the uncertainty represented by the confidence interval.
Best-practice recommendations
- Pre-register: Define the hypotheses, sample size, and α level before collecting data. Avoid p-hacking (tweaking the analysis until p < 0.05).
- Compute the required sample size a priori via a power analysis. Use the available sample size calculators.
- Report the estimated effect and its confidence interval, not just the p-value and the decision.
- Distinguish statistical significance from practical relevance. Interpret results in the context of the real-world problem.
- Check the test's assumptions before interpreting the results.
- Apply a multiple-comparisons correction (Bonferroni, Benjamini-Hochberg…) when running more than one test simultaneously.
- Consider a Bayesian approach as an alternative or complement, especially when the prior distribution carries relevant information.
Key reference
In 2016 the American Statistical Association published an official statement on the use and interpretation of the p-value, recommended reading for anyone working with hypothesis tests: ASA Statement on Statistical Significance and P-Values (Wasserstein & Lazar, 2016).