Sub topic 4
Can you trust the data? Measurement and data checks
This chapter assumes you know basic Lean Six Sigma vocabulary (defect, output Y, input X), the mean and standard deviation, and how to read a histogram or run chart. You should also have a suspected root cause written as a testable hypothesis and a data collection plan. You will use some basic pandas.
A hypothesis test gives a precise answer to the question you ask it. It cannot tell you whether the numbers were recorded correctly. A t-test on cycle times that were mistyped, or measured with a drifting gauge, still returns a clean p-value. The conclusion is then wrong, and the output gives no sign of it.
This chapter covers the checks to run between collecting data and analyzing it. There are two kinds. Data checks look for mistakes in the records. Measurement checks ask whether the measuring method is good enough to see the difference you care about.
Two different questions
Data quality problems and measurement system problems often get mixed together, but they have different fixes.
| Question | What it checks | Typical problem | Typical fix |
|---|---|---|---|
| Is the dataset clean? | Records after they were captured | Missing values, duplicates, typos, impossible values | Clean, re-extract, or exclude with a documented reason |
| Is the measurement system adequate? | How the values were produced | Gauge noise, operator differences, drift, coarse resolution | Repair or calibrate the gauge, standardize the method, retrain |
A clean dataset can still come from a poor gauge, and a good gauge can feed a messy spreadsheet. Check both.
Data checks on the records
Run these checks on every dataset before you plot it. Each one takes a few lines of code.
- Missing values. Find out how many there are and whether they cluster. Missing readings that all come from one shift or one machine bias the result even when the total count is small.
- Duplicates. The same unit recorded twice, often after a system export or a re-keyed form, counts that unit double.
- Inconsistent labels.
"B","b", and"B "are three different groups to software. This silently splits a stratum when you group by it. - Impossible or implausible values. A cycle time of 250 minutes when the process runs near 12 is probably a typo or a unit mix-up (seconds entered as minutes). Do not delete it automatically. Trace it back first.
- Wrong units or scale. Check that all rows use the same unit and that timestamps share a time zone.
import pandas as pd
df = pd.DataFrame({
"unit_id": [101, 102, 103, 103, 104, 105, 106, 107],
"shift": ["A", "A", "B", "B", "b", "B", None, "A"],
"cycle_time": [12.1, 11.8, 13.0, 13.0, 12.9, 250.0, 12.4, None],
})
# 1. Missing values per column
print("Missing values:")
print(df.isna().sum())
# 2. Duplicate unit IDs (the same unit recorded more than once)
dupes = df[df.duplicated(subset="unit_id", keep=False)]
print("\nDuplicated unit_id rows:")
print(dupes)
# 3. Label consistency: compare raw labels with a normalized version
print("\nShift labels as recorded:")
print(df["shift"].value_counts(dropna=False))
df["shift"] = df["shift"].str.strip().str.upper()
# 4. Plausibility: flag values outside the range the process can produce
low, high = 5, 30 # minutes, set from process knowledge, not from this data
out_of_range = df[(df["cycle_time"] < low) | (df["cycle_time"] > high)]
print("\nOut-of-range cycle times:")
print(out_of_range)The script reports a missing shift and a missing cycle time, a duplicated unit 103, a stray lowercase b, and the 250-minute value. Each finding needs a decision. Drop the duplicate, normalize the label, and ask the operator about the 250. Write each decision in a data log with the reason. A later reviewer must be able to tell which rows you removed and why.
Set the plausible range before you look
The low and high limits come from process knowledge, such as a routing sheet or an engineer's judgment. If you set them by looking at the data, you will tend to accept whatever the data contains. That includes the points that hurt your hypothesis.
Do not delete inconvenient points
A common error is removing outliers because they weaken the pattern you hoped to see. Remove a point only when you can show it is an error, such as a typo, a gauge fault, or a unit of a different product. A genuine extreme value is part of the process. Keep it, and consider reporting results with and without it.
Measurement system checks
A measurement system is everything that turns a physical characteristic into a number. That includes the gauge, the operator, the method, and the environment. The numbers you analyze contain the real variation in the process plus the variation added by measuring.
The question is whether the measurement noise is small compared with the effect you are trying to detect. If your suspected cause shifts cycle time by 0.3 minutes and the stopwatch method varies by 1 minute, the data cannot confirm or refute the cause.
The main properties to check:
- Repeatability. The same operator measuring the same item with the same gauge gets the same value, within a small spread.
- Reproducibility. Different operators, or different gauges, get the same value for the same item.
- Bias. The average reading is systematically above or below the true or reference value.
- Stability. Readings do not drift over time. Check this with a run chart of a reference item measured regularly.
- Resolution. The gauge's smallest step is fine enough. A scale that reads to the nearest whole gram cannot show a 0.2 g shift.
For continuous measurements, the full method is a gage R&R study (repeatability and reproducibility). For attribute data, such as pass/fail inspection, the equivalent is an attribute agreement analysis. Both involve several operators measuring the same set of items more than once. A quick version of the first idea is worth knowing. It shows the logic even though it is not a formal gage R&R.
import numpy as np
import pandas as pd
# Two operators each measure the same five parts twice
part = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5] * 2
operator = ["X"] * 10 + ["Y"] * 10
value = [
10.02, 9.98, 10.51, 10.47, 11.03, 10.97, 11.48, 11.52, 12.01, 11.99,
10.33, 10.29, 10.82, 10.78, 11.30, 11.36, 11.79, 11.81, 12.31, 12.27,
]
m = pd.DataFrame({"part": part, "operator": operator, "value": value})
# Repeatability: spread of repeat readings of one part by one operator
cell_var = m.groupby(["part", "operator"])["value"].var(ddof=1)
repeatability_sd = np.sqrt(cell_var.mean())
# Bias between operators: difference of the operator means
op_means = m.groupby("operator")["value"].mean()
operator_gap = op_means["Y"] - op_means["X"]
# Real part-to-part variation: spread of the part averages
part_sd = m.groupby("part")["value"].mean().std(ddof=1)
print(f"Repeatability SD: {repeatability_sd:.2f}")
print(f"Operator Y minus X: {operator_gap:.2f}")
print(f"Part-to-part SD: {part_sd:.2f}")The repeat readings agree to about 0.03, which is tight. Operator Y reads about 0.31 higher than operator X for the same parts, which is a reproducibility problem. The parts themselves differ by about 0.79 (standard deviation), so the gauge can still tell the parts apart. The operator gap is a different matter. If your hypothesis predicts a difference near 0.3 between two groups, and operator X measured one group while operator Y measured the other, the "effect" could come entirely from who measured.
A common rule of thumb for a full gage R&R study is that measurement variation below about 10% of total variation is good and above about 30% is unacceptable. Treat those cutoffs as guidance, and judge them against how large a difference your hypothesis needs to detect.
Does the sample represent the process?
The last check is about how the data was chosen. Good records from the wrong units still mislead.
- Time coverage. Data from one calm week misses the Monday startup or the month-end rush where the problem may live.
- Selection. If inspectors only record units they found suspicious, the sample overstates the defect rate. If operators choose which units to time, they may pick easy ones.
- Operational definition. Everyone must apply the same rule for what counts as a defect or when a cycle starts and stops. Without a written definition, two people record two different things under one column name.
- Collection method changed midway. A new form, a new gauge, or a changed inspection rule partway through the collection period splits the dataset into two kinds of data.
Compare the sample against what you know about the process. For example, check that the share of units per shift in your data roughly matches the share of production per shift. A large mismatch means the sample overrepresents some conditions.
Common mistakes
- Analyzing first and checking later. A surprising result is often a data error. Check the data before you interpret anything.
- Silent cleaning. Fixing or deleting records without a log makes the analysis impossible to review or repeat.
- Trusting the gauge because it is calibrated. Calibration addresses bias against a standard. It says nothing about repeatability, operator differences, or resolution.
- Mixing sources. Combining data from two systems, such as an MES export and a paper log, without checking that definitions and units match.
- Rounding away the signal. Data recorded to the nearest whole minute cannot reveal a 0.3-minute shift. Check the resolution against the effect size.
What to carry forward
If the data checks pass and the measurement system can resolve the effect you are looking for, move on to stratification and graphs. If a check fails, fix the problem first. In some cases you must recollect the data with a better method, because no amount of statistics repairs bad measurements.
Exercise
You want to test whether machine 2 produces longer cycle times than machine 1, using about 0.4 minutes as the smallest difference that matters. A gage study shows the repeat-measurement standard deviation is 0.05 minutes, but the operator who timed machine 1 reads about 0.4 minutes lower than the operator who timed machine 2 on the same reference units. Can you trust a comparison of the two machines' data as collected? What would you do?
Show answer
No. The repeatability is good, since 0.05 is small compared with 0.4. The operator offset of about 0.4 minutes is as large as the difference you want to detect, and it is confounded with the machine, because each operator timed only one machine. Any machine difference in the data could be an operator difference. Fix this before testing. Have one operator time both machines, or have both operators time units on both machines, or correct the offset after confirming it with a documented reference check. Then recollect or re-time the data and run the test.
Exercise
A dataset has 3 cycle times above 200 minutes in a process that normally runs near 12 minutes. The pattern you hope to confirm is stronger if those points are removed. What should you do before removing them?
Show answer
Trace each point to its source to find out whether it is an error (typo, wrong unit, test record) or a genuine event (a breakdown, a long changeover). Remove it only if it is an error you can document, and note the reason in the data log. If the points are genuine, keep them, and consider reporting the analysis both with and without them so the reader can see how much they matter. Deciding by the effect on your result is not a valid reason.