Hypothesis testing explained for engineers, with an example

Updated

A hypothesis test is a structured way to decide whether your data show a real effect or could easily be chance. You start by assuming nothing has changed (the null hypothesis), work out how surprising your data would be under that assumption (the p-value), and reject the assumption only if the data would be quite surprising, usually rarer than 5% of the time. For engineers it answers questions like "is the filler off target?", "did the new tool reduce variation?" or "do the two suppliers differ?", with a known, controlled risk of a false alarm.

The logic in plain words

Every sample varies. Weigh ten bottles from a filler set exactly on target and their average will still not be exactly on target. So when an average comes out 1.3 g high, the real question is: is 1.3 g more than the ordinary sample-to-sample wobble would produce?

A test answers by comparing the difference you saw with the noise you would expect:

test statistic = (what you observed − what H₀ claims) / (standard error of the observation)

A statistic near 0 is what chance alone produces. A statistic far from 0 is hard to explain by chance, and the p-value says exactly how hard.

The logic is one-sided in an important way. A test can give you evidence against the null hypothesis, but it can never prove the null hypothesis true. "No significant difference" means the data are not strong enough to show a difference, not that the difference is zero.

The five steps

  1. State the hypotheses. The null hypothesis H₀ is the "nothing is going on" claim: the mean equals the target, the two suppliers have the same mean. The alternative H₁ is what you would conclude otherwise: the mean differs from the target (two-sided), or is above it (one-sided).
  2. Choose the significance level α before you look at the data. α is the false-alarm risk you accept: 0.05 is common, 0.01 when a false alarm is costly.
  3. Pick the test and check its assumptions. The test depends on the data and the question; see which hypothesis test to use.
  4. Compute the test statistic and the p-value.
  5. Decide and interpret. If p ≤ α, reject H₀. Then report the size of the effect with a confidence interval, because the p-value alone does not say how big the difference is.

Worked example: is the filler on target?

A line fills bottles with a target of 500 g. After a maintenance job, a technician weighs ten bottles:

Bottle12345678910
Weight (g)501.8499.6502.4500.9503.1500.2501.5502.7499.9501.3

Step 1. H₀: μ = 500 g. H₁: μ ≠ 500 g. Two-sided, because a filler that is low is as much a problem as one that is high.

Step 2. α = 0.05.

Step 3. One sample of measurements compared with a target, σ unknown: a one-sample t-test. It assumes the bottles are independent and that weights are roughly normal; with ten values, a quick look at a dotplot for outliers or strong skew is enough.

Step 4. The sample mean is x̄ = 501.34 g and the sample standard deviation is s = 1.1974 g.

SE = s / √n = 1.1974 / √10 = 0.37865 g t = (x̄ − μ₀) / SE = (501.34 − 500) / 0.37865 = 3.539

With n − 1 = 9 degrees of freedom, the probability of a t at least this far from 0 in either direction, if H₀ were true, is:

p = 2 × P(T₉ ≥ 3.539) = 0.0063

Step 5. p = 0.0063 is below α = 0.05, so reject H₀: the data show the filler is not on target. The 95% confidence interval for the mean uses the t value with 9 degrees of freedom, t(0.975, 9) = 2.2622:

x̄ ± t · SE = 501.34 ± 2.2622 × 0.37865 = 501.34 ± 0.857 g, from 500.48 to 502.20 g

The filler is most likely running between 0.5 and 2.2 g over target. At 40,000 bottles a day, the average overfill of 1.34 g is about 54 kg of product given away daily, which is what makes the result worth acting on.

You can check every number in the super calculator: TINV(0.975, 9) gives 2.26215716280, and 2 * (1 - TCDF(3.539, 9)) gives the p-value.

Two ways to be wrong

DecisionH₀ is true (no real change)H₀ is false (real change)
Reject H₀Type I error: false alarm, probability αCorrect: change detected, probability = power
Do not reject H₀CorrectType II error: missed change, probability β

α is set by you. β depends on how big the real change is, how noisy the process is and how many samples you take. Power, 1 − β, is the probability that the test detects a change of a given size.

Power: why small samples miss real changes

Suppose the filler's standard deviation is 1.2 g and you test with α = 0.05, two-sided. The chart shows the probability of detecting a shift of the mean, for samples of 10 and 20 bottles:

Power of a two-sided one-sample t-test (σ = 1.2 g, α = 0.05)0255075100Probability of detecting it (%)n = 10n = 2000.250.50.751.01.251.51.752.0True shift of the mean (g)
Power of a two-sided one-sample t-test (σ = 1.2 g, α = 0.05)

With ten bottles, a real 0.5 g shift is detected only 22% of the time; 1.0 g, 65% of the time; 1.5 g, 94%. Doubling the sample to 20 raises detection of a 1.0 g shift to 94%. At a shift of 0, the "detection" rate is the 5% false-alarm rate, α.

So a non-significant result from a small sample is weak evidence that nothing changed. Before collecting data, decide the smallest change that matters and choose the sample size that gives enough power to detect it, usually 80% or 90%; see how many samples.

Statistical significance is not practical importance

With enough data, tiny differences become significant. Suppose a filler's true mean is 500.05 g, σ = 1.5 g, and an automatic checkweigher records 10,000 bottles. The standard error is 1.5 / √10,000 = 0.015 g, so:

z = 0.05 / 0.015 = 3.33, p = 0.00086

Highly significant, and completely unimportant: 0.05 g is far below anything a customer or an auditor would notice. Always ask how big the effect is, using the confidence interval, and compare it with what matters for the product.

One-sided or two-sided?

A two-sided test asks "is it different?"; a one-sided test asks "is it larger?" (or smaller). A one-sided test has more power in its chosen direction, but it cannot detect a change in the other direction at all, and you must choose it before seeing the data. In the example, the one-sided p-value for "mean above 500 g" would be 0.0032, half the two-sided value. Use one-sided tests only when a change in the other direction is impossible or genuinely irrelevant to the decision.

Assumptions to check

  • Independence. Each measurement is a separate unit, not the same part measured twice (that calls for a paired t-test), and not consecutive readings from a drifting process.
  • A representative sample. Ten bottles taken in one minute say little about a whole shift.
  • Shape. t-tests assume roughly normal data, which matters most for small samples. For skewed data, consider a nonparametric test or a transformation.
  • A stable process. If the process drifts while you sample, the test answers a question about a moving target. A control chart shows whether that is happening.

Common mistakes

  • Treating "not significant" as "no difference". Check the power or the confidence interval: a wide interval that includes both zero and important differences means the data cannot decide.
  • Choosing α or the direction after seeing the data. That inflates the false-alarm rate.
  • Running many tests and reporting the one that is significant. With 20 independent tests at α = 0.05, the chance of at least one false alarm is 64%. See the p-value guide.
  • Ignoring the effect size. Report the difference and its confidence interval, not just p.
  • Using a two-sample test on paired data, or the reverse. See which hypothesis test to use.

Frequently asked questions

What is the difference between α and the p-value?

α is the threshold you set in advance, the false-alarm risk you accept. The p-value is computed from the data. You reject H₀ when p ≤ α. A p-value of 0.0063 with α = 0.05 means reject; the same p-value with α = 0.001 would not.

Why 0.05?

Convention, not law. It balances false alarms against missed changes for many everyday decisions. Use a smaller α when acting on a false alarm is expensive, such as stopping a line, and think about power when missing a change is expensive, such as a safety characteristic.

Is a confidence interval a hypothesis test?

They are two views of the same calculation. A two-sided 95% confidence interval contains exactly the values of μ₀ that a two-sided test at α = 0.05 would not reject. The interval from 500.48 to 502.20 g excludes 500, matching the rejection. The interval also shows the size of the effect, which is why it is often more useful; see confidence intervals explained.

How many samples do I need?

It depends on the smallest difference that matters, the process standard deviation, α and the power you want. The chart above shows the trade-off for one case; how many samples explains the calculation.

Try it with your own data

StatLab SPC is free, open-source statistics for engineers. It runs in your browser, works offline, and never uploads your data.

Open StatLab