Contents/ Part XIII Β· Inference Case Studies/ Chapter 90

Case Study: Manufacturing Quality

A factory line that looks perfectly on-target on average is hiding two real problems. With a one-sample test against spec, an ANOVA across lines, and a defect-by-shift chi-square, we expose a drifting line and a risky night shift, and close Inference Case Studies.

⏱️ ~14 min read
🐍 Notebook included
πŸ“Š Chapter 90

Quality control is inference under pressure: a wrong call ships defects or halts a healthy line. This final case study shows the most important lesson of the Part, that a single summary number can hide real problems, and how the right tests pull them into the light.

250g
The scenario. A plant fills packages to a 250 g target across three lines and two shifts (day/night), and logs any defects. Quality wants to know if the process is healthy, and if not, where to look.
🎯
The three questions

(1) Is the overall mean fill weight on the 250 g target? (2) Do the three lines differ in average weight? (3) Is the defect rate associated with shift?

1

The Data & The Questions

One row per sampled unit: its line, shift, measured fill_weight_g, and whether a defect was found. The overall average weight is about 249.85 g, reassuringly close to 250.

πŸ“‚ Dataset Β· case-study-manufacturing-quality--manufacturing_quality.xlsx

One row per unit with line (three lines), shift (day/night), fill_weight_g, defect (0/1), and defect_type.

If you stopped at the overall average, you would sign off the process as healthy. That is the trap this chapter is built to expose: an aggregate on target can hide one line running light, another running heavy, and defects clustering in one shift. We test all three questions before concluding anything.

2

Three Questions, Three Tests

Each question's structure picks its tool: one mean vs a target, three groups compared, and a rate by category.

QuestionStructureTestH₀ / H₁
On the 250 g target?one mean vs a valueone-sample t-testμ = 250 / μ ≠ 250
Do the lines differ?3 independent groups, numericone-way ANOVA + Tukeylines equal / a line differs
Defects tied to shift?2 categorical variableschi-square independenceindependent / associated

The subtle point is that Q1 and Q2 are different questions. The process can be on target on average while individual lines drift in opposite directions and cancel out. A one-sample test against the target will not catch that, only comparing the lines will. This is precisely the trap to check for.

3

The Analysis & Results

The one-sample test checks the aggregate; ANOVA-plus-Tukey finds the drifting line; chi-square ties defects to shift.

On target on average, but Line-2 is drifting light 250 g 250.5Line-1 Line-2248.7 (light) 250.4Line-3 slightly heavy
QuestionResultReading
Q1 mean vs 250 g249.85 g, t = −0.98, p ≈ 0.33on target (in aggregate)
Q2 ANOVA across linesF = 15.7, p ≈ 10⁻⁷lines differ
Q2 TukeyLine-2 vs Line-1 (−1.8 g) and vs Line-3 (−1.7 g) differ; 1 ≈ 3Line-2 is the culprit
Q3 defect × shiftday 6.0% vs night 19.6%, χ² = 12.8, p ≈ 0.0003night is worse

The whole lesson in one dataset. The overall mean is statistically on target (p ≈ 0.33), yet the ANOVA says the lines differ (p ≈ 10⁻⁷, η² ≈ 0.09, a moderate effect) and Tukey pins it on Line-2, running about 1.7 g light while Lines 1 and 3 sit slightly heavy, the errors cancel in the average. Separately, defects are three times more common at night (19.6% vs 6.0%, p ≈ 0.0003). Two real, actionable problems hidden behind a healthy-looking headline.

Assumptions, checked. Before trusting the line ANOVA we confirm its conditions: Levene's test (p ≈ 0.79) for equal variance and a residual QQ plot with Shapiro (p ≈ 0.58) for normal residuals, both pass, and a distribution-free Kruskal-Wallis cross-check agrees. Had a check failed, the remedy is Welch's ANOVA for unequal variance or Kruskal-Wallis for non-normality.

4

The Statistician's Report

How to brief the plant manager, with the punchline first.

πŸ“‹ Statistician's report · to the plant manager

Findings: on-target on average, but two real problems

What we found. Overall the line hits its 250 g target on average, so a single headline number would say "all good." It is not. Line-2 is under-filling by about 1.7 grams while Lines 1 and 3 run slightly heavy, the over- and under-fills cancel out in the plant average but are real. And defects are about three times more common on the night shift (about 20% vs 6%).

How confident are we? The line difference is highly unlikely to be chance (less than 1 in a million), and the careful pairwise comparison isolates Line-2. The night-shift defect difference is also clear (about 1 in 3,000 by chance).

What to do. (1) Recalibrate Line-2's filler, it risks under-weight complaints, while the heavy lines give away product. (2) Investigate the night shift, staffing, fatigue, lighting, or maintenance timing, because that defect rate is the bigger cost.

Caveats. The on-target average is a warning to monitor each line separately, not just the plant total, aggregates can mask offsetting drift. This is a one-time snapshot; set up ongoing control charts to catch drift as it happens.

πŸ€–
In the field

This is statistical process control, the ancestor of modern anomaly detection and monitoring. The "aggregate hides the problem" trap is the same one that bites dashboards and ML metrics: a flat overall accuracy can hide a subgroup the model fails on. Segment, then test.

🐍

Run the quality analysis in Python

The companion notebook explores by line and by shift first (so the hidden problems surface), then uses statsmodels (DescrStatsW, anova_lm, pairwise_tukeyhsd) for the spec test, the ANOVA, and the post-hoc, and scipy for the defect-by-shift chi-square.

πŸ““ View Notebook (code & outputs) β–Ά Open in Colab ⬇ View / Download on GitHub

View opens the rendered notebook instantly (no setup). Open in Colab runs & edits it live in your browser. To run locally, install numpy, pandas, scipy, matplotlib, statsmodels, and openpyxl and launch jupyter notebook.

πŸŽ“ Key Takeaways

  • βœ“Aggregates can lie: the plant mean is on target (p ≈ 0.33), yet the lines genuinely differ.
  • βœ“One mean vs a target → one-sample t; 3 lines → ANOVA + Tukey to find the culprit (Line-2).
  • βœ“Defects by shift → chi-square: night 19.6% vs day 6.0% (p ≈ 0.0003), a real, actionable gap.
  • βœ“Always segment before declaring a process healthy; monitor each line, not just the total.
  • βœ“Inference Case Studies complete: five case studies, raw question to statistician's report, the whole inference playbook in action.
5

Quiz: Test Yourself

Eight quick questions on this case study. Answer them, hit Check Answers, and keep refining until you score 100%. Your progress is saved, so you can hop back to the chapter and return anytime.

🏁
That completes Inference Case Studies

Across five case studies you turned raw business questions, A/B tests, group comparisons, a clinical trial, a survey, and a factory line, into the right test, run correctly and reported honestly. Next the book turns to relationships between variables: Correlation & Association, starting with covariance.