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.

Interactive sections
  1. One-sample z-test
  2. Decisions and errors
  3. Alpha, beta, and power
  4. Sample size for a fixed confidence interval

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$.
Standard error
—
z statistic
—
p-value
—
α
—

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.
RealityDecisionOutcome
$H_0$ trueDo not reject $H_0$Correct decision
$H_0$ trueReject $H_0$Type I error
$H_1$ trueDo not reject $H_0$Type II error
$H_1$ trueReject $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.$$
α
—
1 − α
—
β
—
Power = 1 − β
—

Four possible outcomes

RealityDo not reject $H_0$Reject $H_0$
$H_0$ trueCorrect decision
Probability = 1 − α
Type I error
Probability = α
$H_1$ trueType 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$.
Critical z*
—
Unrounded n
—
Required n
—
Actual margin
—