Sub topic 2
The test selection map
You should know the mean, median, and standard deviation, and be able to read histograms and box plots. You should also understand the difference between a sample and a population, and the purpose of the Analyze phase in DMAIC.
Y is the output you measure, and X is the input you suspect drives it. Classify both before choosing a test. Y and X are each either continuous (measured on a scale, such as cycle time) or discrete (counted in categories, such as pass or fail).
| Y type | X type | Starting test |
|---|---|---|
| Continuous | One sample against a target | One-sample t-test |
| Continuous | Two groups, different units | Two-sample t-test |
| Continuous | Two measurements on the same units | Paired t-test |
| Continuous | Three or more groups | One-way ANOVA |
| Discrete | Groups | Chi-square or proportion test |
Checking whether the data are normal
A normality test asks whether the data could plausibly come from a normal (bell-shaped) distribution. The Shapiro-Wilk test is a common choice. A p-value above 0.05 means the data give no strong evidence against normality. With small samples, the test has little power, so also inspect a histogram.
Checking whether variances are equal
Levene's test compares the spread of two or more groups. A p-value above 0.05 suggests equal variances. If variances differ, use Welch's t-test, which does not assume equal variances.
import numpy as np
from scipy import stats
rng = np.random.default_rng(1)
before = rng.normal(50, 2, 20)
after = before + rng.normal(1, 1, 20)
print("Shapiro-Wilk before p =", stats.shapiro(before).pvalue)
print("Levene p =", stats.levene(before, after).pvalue)
# Welch two-sample t-test, safe when variances may differ
print("Welch p =", stats.ttest_ind(before, after, equal_var=False).pvalue)Comparing one sample with a target
The one-sample t-test compares the sample mean with a known target, such as a specification of 50 mm. It assumes the data are roughly normal.
Comparing two groups: two-sample and paired t-tests
Use a two-sample t-test when each group contains different units, such as parts from two machines. Use a paired t-test when the same units are measured twice, such as a part measured before and after a fix. The paired test works on the differences between each pair.
# Paired test on the same units (before and after)
print("Paired p =", stats.ttest_rel(before, after).pvalue)
# One-sample test against target 50
print("One-sample p =", stats.ttest_1samp(before, popmean=50).pvalue)Exercise
A team measures the same 15 parts before and after a fixture change. Which test should they use, and why?
Show answer
A paired t-test, because each part is measured twice and the differences are the unit of analysis.