Hypothesis Testing
Run a z-test step by step and see the test statistic, rejection region and p-value
A machine should fill bottles with 500 ml on average. An inspector weighs a sample of n bottles and tests whether the mean fill is off target.
Distribution of z if H₀ is true (standard normal)
- z statistic
- 1.500
- p-value
- 0.1336
- Critical value
- ±1.960
- Decision
- Keep H₀
- 1Hypotheses. H₀: μ = 500 ml (the machine is on target). H₁: μ ≠ 500 ml. Significance level α = 0.05.
- 2Standard error. SE = σ/√n = 4.00/√25 = 0.800
- 3Test statistic. z = (x̄ − μ₀)/SE = (501.20 − 500)/0.800 = 1.500
- 4p-value. p = 2 · P(Z ≥ 1.500) = 0.1336
- 5Decision. p > α (0.1336 > 0.05), equivalently the rejection rule |z| ≥ 1.960 is not met, so we fail to reject H₀. There is not enough evidence that the mean fill differs from 500 ml. This does not prove that μ = 500.
Bottles are drawn from a normal distribution with this mean and σ = 4 ml.
Draw one sample to fill in x̄ above, or run 1,000 tests to see how often this test rejects H₀ in the chosen world.
How a hypothesis test works
A hypothesis test is a proof by contradiction with uncertainty. You start from a null hypothesis H₀ that pins down the population mean, say μ = 500 ml, and an alternative H₁ that says what you suspect instead: the mean is different, lower or higher.
Assuming H₀ is true, the sample mean x̄ should land near μ₀, with a spread given by the standard error. The test statistic z = (x̄ − μ₀)/(σ/√n) measures how far away it actually landed, in standard errors. Under H₀ it follows a standard normal distribution, so you can ask how unusual the observed value is. That probability is the p-value.
If the p-value is at most the significance level α, the data would be rare under H₀, so you reject H₀. Otherwise you fail to reject it, which is not the same as showing it is true. When σ is unknown you use the sample standard deviation s instead, and the statistic follows a t distribution with n − 1 degrees of freedom.
Null hypothesis H₀
Test statistic
p-value
Decision at level α
Key formulas
One-sample z statistic (σ known)
z = (x̄ − μ₀) / (σ / √n)
- x̄
- sample mean
- μ₀
- mean claimed by H₀
- σ / √n
- standard error of x̄
One-sample t statistic (σ unknown)
t = (x̄ − μ₀) / (s / √n)
- s
- sample standard deviation; compare with a t distribution with n − 1 df
Decision rule
reject H₀ if p-value ≤ α (equivalently, if the statistic falls in the rejection region)
p-values and rejection regions
| Test | H₁ | p-value | Reject at α = 0.05 |
|---|---|---|---|
| Two-sided | μ ≠ μ₀ | 2 · P(Z ≥ |z|) | |z| ≥ 1.960 |
| Left-tailed | μ < μ₀ | P(Z ≤ z) | z ≤ −1.645 |
| Right-tailed | μ > μ₀ | P(Z ≥ z) | z ≥ 1.645 |
How to use this visualizer
- 1Choose the test (z if σ is known, t if not), the alternative hypothesis and the significance level α.
- 2Move the sample mean slider. The black line is the observed statistic, the orange area is its p-value and the red area is the rejection region.
- 3Read the step-by-step panel: it fills in the standard error, the statistic, the p-value and the decision with the current numbers.
- 4Increase n with the same x̄. The standard error shrinks, the statistic grows and a small difference becomes significant.
- 5In the simulation panel, set the true mean to 500 ml (H₀ true) and run 1,000 tests. About α of them reject H₀: these are Type I errors.
- 6Move the true mean away from 500 and run again. Now the rejection rate is the power of the test, and the misses are Type II errors.
Common misconception
The p-value is not the probability that H₀ is true. It is computed assuming H₀ is true, and tells you how surprising the data would be in that case. A p-value of 0.03 means "data this extreme would happen 3% of the time if H₀ held", not "there is a 3% chance H₀ is right". Likewise, a large p-value only says the data are compatible with H₀, not that H₀ has been proven.Practice problems
Problem 1: Is the filling machine on target?
Show solutionHide solution
SE = σ/√n = 4/√36 = 4/6 = 0.667 ml
z = (498.6 − 500)/0.667 = −1.4/0.667 = −2.10
p = 2 · P(Z ≤ −2.10) = 2 × 0.0179 = 0.0357
At α = 0.05: 0.0357 ≤ 0.05, so reject H₀. At α = 0.01: 0.0357 > 0.01, so fail to reject.
z = −2.10, p ≈ 0.036: reject at α = 0.05, but not at α = 0.01
Problem 2: Battery life claim
Show solutionHide solution
σ is unknown, so use a t-test with n − 1 = 9 degrees of freedom.
SE = s/√n = 1.5/√10 = 0.474 hours
t = (19.1 − 20)/0.474 = −1.897
Critical value: t₀.₀₅(9) = −1.833. Since −1.897 ≤ −1.833, the statistic is in the rejection region.
p = P(T₉ ≤ −1.897) ≈ 0.045 ≤ 0.05
t ≈ −1.90, p ≈ 0.045: reject H₀; the data suggest the batteries last less than 20 hours
Related topics
Discussion
Questions, ideas or a different approach? Join the conversation.