The Logic of Hypothesis Testing
Every hypothesis test begins with two complementary claims about the world. The null hypothesis $H_0$ represents the status quo or the skeptical position — typically a statement of no effect, no difference, or no association. The alternative hypothesis $H_1$ (or $H_a$) captures the claim we actually want to investigate. The asymmetry is intentional and important: we never prove $H_0$; we can only accumulate evidence that makes it implausible.
The classical setup is:
for a two-sided test, or $H_1: \mu > \mu_0$ / $H_1: \mu < \mu_0$ for one-sided alternatives. The choice of one- vs. two-sided should be made before looking at the data based on the scientific question — not retroactively based on which direction happens to look significant.
Test Statistics and Null Distributions
A test statistic is a single number computed from the sample that summarizes the evidence against $H_0$. Its key property is that its sampling distribution is known (or can be approximated) when $H_0$ is true. For a one-sample t-test:
where $\bar{X}$ is the sample mean, $s$ is the sample standard deviation, and $n$ is the sample size. Under $H_0$, this statistic follows a $t$-distribution with $n-1$ degrees of freedom — exactly when the data are normal, approximately via the Central Limit Theorem for large $n$.
The P-Value: Definition and Correct Interpretation
The p-value is the probability of observing a test statistic at least as extreme as the one computed, assuming $H_0$ is true:
A small p-value means the observed data would be rare under $H_0$ — it is evidence against the null. A large p-value means the data are consistent with the null, not that the null is true.
What a P-Value Is Not
Three misconceptions dominate practice:
- The p-value is not the probability that <!--MATHBLOCK20--> is true. That would require a prior probability on <!--MATHBLOCK21-->, which is the domain of Bayesian inference.
- A p-value below 0.05 does not mean the effect is practically important. With <!--MATHBLOCK22-->, a 0.001-unit difference will be wildly significant.
- A non-significant result does not confirm <!--MATHBLOCK23-->. It means the data were insufficient to detect an effect — which could exist but be small or the study underpowered.
The 0.05 threshold, enshrined by Fisher in the 1920s, is a convention, not a law of nature. Many journals now recommend reporting the exact p-value alongside effect sizes and confidence intervals.
Confidence Intervals as Companions to P-Values
A 95% confidence interval (CI) and a two-sided test at $\alpha = 0.05$ are dual: you reject $H_0: \mu = \mu_0$ at level $\alpha$ if and only if $\mu_0$ falls outside the $(1-\alpha)$ CI. Reporting the CI alongside the p-value communicates the direction and magnitude of the effect, not just its significance.
import numpy as np
from scipy import stats
rng = np.random.default_rng(42)
data = rng.normal(loc=5.3, scale=2.0, size=40) # true mean slightly above 5
# One-sample t-test: H0: mu = 5
t_stat, p_val = stats.ttest_1samp(data, popmean=5.0)
ci = stats.t.interval(0.95, df=len(data)-1,
loc=np.mean(data),
scale=stats.sem(data))
print(f"t = {t_stat:.3f}, p = {p_val:.4f}")
print(f"95% CI: ({ci[0]:.3f}, {ci[1]:.3f})")
print(f"Sample mean: {np.mean(data):.3f}")The output reveals whether $\mu_0 = 5$ is plausible given the data, and the CI communicates the range of mean values consistent with the data.
Assumptions and Their Violations
The t-test assumes:
- Independence of observations.
- Approximate normality of the sampling distribution of <!--MATHBLOCK30--> (not necessarily of the raw data; CLT helps for <!--MATHBLOCK31-->).
- For two-sample tests: homogeneity of variance (relaxed by Welch's t-test, which is now the default in most software).
When these assumptions are doubtful, Section 4 covers nonparametric alternatives. Independence is the hardest to repair statistically — it requires redesigning the data collection.