Sub topic 2
Stratifying data to expose differences
This chapter assumes you know the DMAIC phases, the terms defect and output Y, the mean and standard deviation, and how to read histograms and run charts. Stratifying means splitting your data into groups by a factor you suspect is linked to the problem, such as shift, machine, or supplier. If the defect rate differs between groups, the suspected cause gains support.
Stratifying data to expose differences
Start with a flag for each unit (1 for defective, 0 for good) and the factor you suspect. Then compare defect rates across the groups.
import pandas as pd
# One row per unit: the suspected factor (shift) and the defect flag
df = pd.DataFrame({
"shift": ["A", "A", "A", "B", "B", "B", "B", "A"],
"defect": [0, 1, 0, 1, 1, 0, 1, 0],
})
summary = df.groupby("shift")["defect"].agg(rate="mean", units="count")
print(summary)Looking before testing: graphs that support or challenge the cause
Plot the data before you run any test. A boxplot of cycle time per group shows whether the groups overlap, how spread out they are, and whether outliers distort the picture. A Pareto chart of defect counts by group shows which group contributes most of the problem.
Choosing and running a hypothesis test
Pick the test by data type. For continuous data such as cycle time, use a two-sample t-test. Welch's version does not assume equal variance in the two groups, so it is the safer default. For defect counts across groups, use a chi-square test of independence.
import numpy as np
from scipy import stats
# Cycle times in minutes under the old and suspected setups
old = np.array([12.1, 11.8, 12.4, 12.0, 12.6, 11.9, 12.3, 12.2])
suspect = np.array([13.0, 12.8, 13.4, 12.9, 13.1, 13.5, 12.7, 13.2])
result = stats.ttest_ind(old, suspect, equal_var=False)
print(f"t = {result.statistic:.2f}, p = {result.pvalue:.4f}")Reading p-values and understanding error risk
The p-value is the probability of seeing a difference at least as large as yours if the two groups actually had the same mean. Compare it with a significance level (alpha) that you set before looking at the data, usually 0.05. A small p-value is evidence against equal means. It does not measure how large or important the difference is.
Two errors can occur. A Type I error rejects a true "no difference" conclusion (a false alarm). A Type II error fails to detect a real difference (a missed cause).
| Error type | What happens | Risk controlled by |
|---|---|---|
| Type I | Declare a difference that does not exist | Significance level (alpha) |
| Type II | Miss a difference that does exist | Sample size and power |
Exercise
Exercise
A test on cycle time returns p = 0.03 with alpha set to 0.05 before the data was collected. What can you conclude, and what can you not conclude?
Show answer
The data show evidence that mean cycle time differs between the groups at the chosen risk level, with a 5% chance of a false alarm. The test does not show how large the difference is, and it does not prove the suspected setup caused it.