Sub topic 7
Choosing and Running a Hypothesis Test
Assume you already have a suspected root cause, a measurable process output, and a data collection plan. You also know basic descriptive statistics and can read common process charts. A hypothesis test helps you judge whether an observed difference is large enough to challenge the assumption that the suspected cause has no effect.
Start with the Question
Write the comparison before looking at the result:
- Null hypothesis (H₀): the suspected cause has no measurable effect.
- Alternative hypothesis (H₁): the suspected cause is associated with a measurable difference.
For example:
- H₀: Mean cycle time is the same for the old and suspected setups.
- H₁: Mean cycle time differs between the two setups.
The alternative can be two-sided, meaning “different,” or one-sided, meaning “higher” or “lower.” Use a one-sided test only when the direction was justified before analyzing the data.
Choose the test from the type of output and the comparison:
| Data and question | Common test |
|---|---|
| Continuous output, two independent groups | Welch two-sample t-test |
| Continuous output, three or more groups | ANOVA |
| Count or defect classification by groups | Chi-square test of independence |
A continuous output is measured on a numerical scale, such as minutes or millimeters. A count or classification records categories, such as defective and good units.
Run a Test for Two Continuous Groups
Suppose cycle times were collected under an old setup and a suspected setup. Welch’s t-test compares the group means without requiring equal variances.
import numpy as np
from scipy import stats
setup_old = np.array([12.1, 11.8, 12.4, 12.0, 12.6, 11.9, 12.3, 12.2])
setup_suspect = np.array([13.0, 12.8, 13.4, 12.9, 13.1, 13.5, 12.7, 13.2])
result = stats.ttest_ind(
setup_old,
setup_suspect,
equal_var=False,
)
print(f"t = {result.statistic:.2f}, p = {result.pvalue:.4f}")
alpha = 0.05
if result.pvalue < alpha:
print("Evidence that mean cycle time differs.")
else:
print("No evidence of a difference in mean cycle time.")The significance level, written as α, is the threshold selected before testing. An α of 0.05 means you accept a 5% risk of rejecting a true null hypothesis under the test assumptions.
The p-value is the probability of observing a result at least this extreme if H₀ were true. A p-value below α gives evidence against H₀. It does not prove that the suspected cause is true, and it does not measure the size or practical importance of the effect.
Test Defect Counts by Group
For defect data, create a contingency table. Each row can represent a shift, machine, or operator group. Columns can represent defective and good units.
import numpy as np
from scipy import stats
table = np.array([
[18, 182], # Shift A: defective, good
[41, 159], # Shift B: defective, good
])
chi2, p, dof, expected = stats.chi2_contingency(table)
print(f"chi2 = {chi2:.2f}, dof = {dof}, p = {p:.4f}")
print("Expected counts if shift had no effect:")
print(expected)The expected counts describe what the table would look like if defect status and shift were unrelated. Very small expected counts can make the chi-square approximation unreliable. Combine sparse categories when that is meaningful, or use an exact test for a small two-by-two table.
Interpret the Result in Context
Report the group sizes, descriptive statistics, estimated difference, test name, p-value, and practical consequence. For example: “Shift B had a 12% higher defect rate than Shift A. The chi-square test gave p = 0.01, so the data challenge the no-difference assumption. We will investigate shift-specific conditions before changing the process.”
Use a graph and the raw counts alongside the test. A test can detect a small effect in a large sample, while a meaningful effect may remain uncertain in a small sample.
Exercise
A t-test returns p = 0.18 with alpha = 0.05. What should you conclude?
Show answer
Do not reject the null hypothesis. The data do not provide sufficient evidence of a difference at the chosen significance level. This does not prove that the groups are identical.