Sub topic 5
Stratifying Data to Expose Differences
This chapter assumes you know basic Lean Six Sigma vocabulary (defect, output Y, input X), can read a histogram and a run chart, and can compute a mean and a standard deviation. You should also have a suspected root cause from a fishbone diagram or 5 Whys, and a data collection plan that records the factor you suspect.
What stratification is and why it matters
Stratification means splitting process data into groups, called strata, by a factor that might matter. Typical factors are shift, machine, operator, supplier, product type, day of week, and location. You then compare the groups on the output Y.
Pooled data hides structure. A process can show an overall defect rate of 6%, which looks unremarkable. Underneath, one machine may run at 1% and another at 11%. The average describes neither of them. Stratifying is how you find out whether your suspected cause leaves a visible trace.
In the verification workflow, stratification sits between checking data quality and drawing graphs. It is a cheap first check. It does not prove anything, but it tells you whether a formal test is worth running and which comparison to run.
Choosing the stratification factor
Pick factors from two sources.
- The hypothesis itself. If the suspected cause is "the night shift skips the pre-start check," the factor is shift. This is the main stratification and it is the one the verification depends on.
- Other plausible sources of variation. Machine, material lot, and operator may also affect Y. Recording these lets you check whether they explain the pattern instead.
The factor must have been recorded when the data was collected. If the shift was never written down, you cannot add it afterward without guessing. This is why the data collection plan must name the stratification factors before collection begins.
A good stratification factor has these properties:
- It is categorical or can be turned into categories, such as time of day into morning, afternoon, and night.
- Each category has enough observations to say something. A stratum with three units tells you almost nothing.
- Categories are mutually exclusive, so each unit belongs to exactly one group.
- It matches how the process actually varies. Splitting by day of week is useless if nothing changes between days.
Stratifying a defect flag
When Y is a yes/no outcome, such as defective or not, summarize each stratum with a defect rate and a unit count. The count matters as much as the rate, because a rate based on few units is unstable.
import pandas as pd
# Defect records: one row per unit, with the stratification factor 'shift'
df = pd.DataFrame({
"shift": ["A", "A", "A", "B", "B", "B", "B", "A"],
"defect": [0, 1, 0, 1, 1, 0, 1, 0],
})
# Defect rate and unit count per shift
summary = df.groupby("shift")["defect"].agg(rate="mean", units="count")
print(summary)Because defect is coded 0 or 1, its mean is the defect rate. For shift A, one defect in four units gives 0.25. For shift B, three in four gives 0.75. The difference looks large. But each shift has only four units, so this table cannot support a conclusion. It shows the mechanics. With real data you would want dozens or hundreds of units per stratum, and you would follow the table with a test.
Always read the rate and the count together.
| Shift | Units | Defect rate | How to read it |
|---|---|---|---|
| A | 4 | 25% | Too few units to trust |
| B | 4 | 75% | Too few units to trust |
| A | 200 | 9% | Stable enough to compare |
| B | 200 | 20.5% | Stable enough to compare |
Stratifying continuous data
For continuous Y, such as cycle time in minutes, summarize each stratum with its center and spread. Use the mean and the standard deviation, and add the median when outliers are likely. Two groups with the same mean can still differ in spread, and a difference in spread is itself evidence of a different process behavior.
import pandas as pd
df = pd.DataFrame({
"machine": ["M1"] * 6 + ["M2"] * 6,
"cycle_min": [12.1, 11.8, 12.4, 12.0, 12.6, 11.9,
13.0, 12.8, 13.4, 12.9, 13.1, 13.5],
})
summary = df.groupby("machine")["cycle_min"].agg(
n="count", mean="mean", median="median", std="std"
)
print(summary.round(2))Compare the groups on all four columns. Check the spread: if one machine has a standard deviation three times larger than another, the problem may be variation and not the average.
Stratifying by more than one factor
Sometimes the effect only appears when two factors combine. A cross-tabulation shows the defect rate for each combination.
import pandas as pd
df = pd.DataFrame({
"shift": ["A", "A", "A", "A", "B", "B", "B", "B"] * 3,
"machine": ["M1", "M1", "M2", "M2", "M1", "M1", "M2", "M2"] * 3,
"defect": [0, 0, 1, 0, 0, 1, 1, 1] * 3,
})
table = df.pivot_table(
index="shift", columns="machine", values="defect",
aggfunc=["mean", "count"],
)
print(table)In this table, read the mean block as defect rates and the count block as units per cell. If shift B is worse on both machines, shift is a candidate cause. If shift B is worse only on machine M2, the cause is more likely tied to that machine, or to how shift B uses it.
Do not stratify by too many factors at once. Each added factor multiplies the number of cells, and the units get spread thin. Three factors with four levels each give 64 cells. Start with the factor named in your hypothesis, then add one other factor at a time.
Reading the result
Stratification produces three possible outcomes.
- A clear difference between strata. The data is consistent with the suspected cause. Move on to graphs and a test to see whether the difference is larger than chance.
- No visible difference. The data does not support the cause as stated. Either the cause is wrong, the factor was defined too coarsely, or the effect is real but small relative to the noise. Revisit the hypothesis before collecting more data.
- A difference in a different factor than the one you suspected. This is a lead, not a verification. Write it down as a new hypothesis and test it separately.
Common errors
- Stratifying after the fact on a factor you did not record. If you reconstruct shift from timestamps, check that the shift boundaries match how the plant actually ran.
- Ignoring group size. A 40% defect rate in a stratum of five units is not a finding.
- Slicing until something appears. If you test ten factors and report the one that differs, you have likely found chance. Choose the factors from the hypothesis before looking, and record why you chose them.
- Mixing definitions across strata. If shift A inspects every unit and shift B inspects a sample, the defect rates are not comparable. This is a measurement quality problem and it should have been caught in the data quality check.
- Unbalanced strata. If one machine ran mostly easy products and the other ran hard ones, product type is tangled with machine. Cross-tabulate product type too.
- Treating a continuous factor as a category without thought. Splitting temperature at an arbitrary cut point can create or hide differences. Prefer a scatter plot for continuous inputs, covered in the next chapter.
A worked scenario
A packaging line shows a 14% rework rate. The team suspects that the second shift, which has newer operators, causes most of it. They have 400 units per shift from the last three weeks, with shift, machine, and defect recorded.
- They stratify by shift. Shift 1 has a 9% rework rate and shift 2 has 19%.
- They stratify by shift and machine. On machine M1, the rates are 8% and 10%. On machine M2, they are 10% and 31%.
- They see that the shift effect is concentrated on M2, so the hypothesis changes. The suspected cause is now "operators on shift 2 set up M2 differently."
- They check unit counts per cell and find that shift 2 ran M2 for most of its output. This is why the pooled shift difference looked large.
The refinement in step 3 is the main benefit of stratification. It sharpened the claim into one that can be tested, and it pointed to where to collect the next data. No cause has been verified yet. A hypothesis test on the M2 comparison is the next step.
Exercise
A team compares defect rates by supplier. Supplier X shows 2 defects in 10 units (20%). Supplier Y shows 30 defects in 400 units (7.5%). A team member concludes that supplier X is much worse. What is wrong with this conclusion, and what would you do next?
Show answer
Supplier X has only 10 units, so its rate is unstable. A single extra or missing defect changes it by 10 percentage points. The comparison cannot support a conclusion. Collect more units from supplier X, or run a test that accounts for the small count, such as a chi-square or Fisher exact test, before claiming a difference. Also check that both suppliers were inspected the same way.
Exercise
A pooled defect rate is 10%. Stratifying by machine gives M1 = 10% and M2 = 10%, and stratifying by shift gives A = 10% and B = 10%. Does this mean machine and shift are unrelated to defects?
Show answer
Not necessarily. Each single-factor split can look flat while a combination of the two differs, for example when only shift B on machine M2 has a high rate and another cell offsets it. Cross-tabulate machine by shift and check the counts per cell. If every cell is still near 10% with adequate counts, then neither factor, alone or combined, is supported as a cause.