Hypothesis Testing, Errors, Power, and Sample Size
This page connects the main ideas used in a one-sample z-test: the test statistic, p-value, Type I and Type II errors, significance level, power, and confidence-interval sample-size planning.
1. One-sample z-test
Use this test when the population standard deviation $\sigma$ is known.
$$H_0:\mu=\mu_0$$
$$\boxed{z=\frac{\bar X-\mu_0}{\sigma/\sqrt n}}$$
Enter the null mean $\mu_0$, observed sample mean $\bar X$, known population standard deviation $\sigma$, and sample size $n$. If $X$ is a single observation rather than a sample mean, set $n=1$.
2. Decisions, Type I error, and Type II error
$$p\le\alpha\Rightarrow\text{Reject }H_0$$
$$p>\alpha\Rightarrow\text{Do not reject }H_0$$
In a real study the p-value is calculated from the observed data. Here it can be moved manually to explore the logic of decisions and errors.
| Reality | Decision | Outcome |
|---|
| $H_0$ true | Do not reject $H_0$ | Correct decision |
| $H_0$ true | Reject $H_0$ | Type I error |
| $H_1$ true | Do not reject $H_0$ | Type II error |
| $H_1$ true | Reject $H_0$ | Correct decision |
3. Alpha, beta, and statistical power
$$P(\text{Type I error}\mid H_0)=\alpha,\qquad P(\text{correctly do not reject }H_0\mid H_0)=1-\alpha$$
$$P(\text{Type II error}\mid H_1)=\beta,\qquad P(\text{correctly reject }H_0\mid H_1)=1-\beta$$
$$\boxed{\text{Power}=1-\beta}$$
This simulator uses a standardized effect size $d$. Under $H_1$, the z-statistic distribution is shifted by $$\lambda=d\sqrt n.$$
Four possible outcomes
| Reality | Do not reject $H_0$ | Reject $H_0$ |
|---|
| $H_0$ true | Correct decision Probability = 1 − α | Type I error Probability = α |
|---|
| $H_1$ true | Type II error Probability = β | Correct decision / Power Probability = 1 − β |
|---|
Reducing Type I error: use a smaller $\alpha$, correct for multiple testing when appropriate, and pre-specify hypotheses and analysis decisions.
Reducing Type II error: increase $n$, reduce measurement variability, and use an efficient design.
Trade-off: for fixed $n$ and effect size, lowering $\alpha$ usually increases $\beta$. Increasing $n$ can recover power while keeping $\alpha$ small.
4. Sample size for a fixed confidence interval
For a confidence interval for a population mean with known $\sigma$:
$$\bar X\pm z_{1-\alpha/2}\frac{\sigma}{\sqrt n}$$
If the desired margin of error is $E$:
$$E=z_{1-\alpha/2}\frac{\sigma}{\sqrt n}$$
$$\boxed{n=\left(\frac{z_{1-\alpha/2}\sigma}{E}\right)^2}$$
Always round $n$ up. If the desired total interval width is $W$, then $E=W/2$.