Build a control chart
Inputs
data(required): The measurements in time order with dates or sequence numbers, the unit, and for p or c charts the sample size or inspection area per point. Include any known process changes and their dates.chart_type(optional; one of: individuals, xbar-r, p, c; default: individuals): individuals (single measurements, I-MR), xbar-r (subgroups of 2 to 10 measurements), p (proportion defective, sample sizes may vary) or c (count of defects in a constant area of opportunity).
Arguments fill these in order. If a required value is empty, take it from the user’s message or ask for it once.
- Check the data: time order, number of points, the measurement unit, and any gaps. If points are not in time order or have no sequence, ask for it and stop. With fewer than 20 points (or 20 subgroups), compute provisional limits and label them as such.
- Check that $chart_type fits the data. Individual continuous values suit individuals (I-MR); rational subgroups of 2 to 10 suit xbar-r; defective or not per unit with a sample size per period suits p; defect counts over a constant area of opportunity suit c. If it does not fit, say which chart fits and why, and build that one.
- Choose the baseline period: the points used to compute limits, ideally a stable stretch before a known change. If a known process change occurred, compute separate limits before and after it.
- Compute the centre line and limits, showing the working:
- Individuals: X̄ and the average moving range MR̄; limits X̄ ± 2.66 × MR̄; moving range chart upper limit 3.267 × MR̄.
- Xbar-R: grand mean and R̄; limits X̄ ± A2 × R̄; range chart D3 × R̄ and D4 × R̄, with A2, D3, D4 for the subgroup size (n = 2: 1.880, 0, 3.267; n = 3: 1.023, 0, 2.574; n = 4: 0.729, 0, 2.282; n = 5: 0.577, 0, 2.114).
- p: p̄ = total defectives ÷ total inspected; limits p̄ ± 3 × √(p̄(1 − p̄) / nᵢ) per point when sizes vary, floored at 0.
- c: c̄ ± 3 × √c̄, floored at 0.
- Apply the detection rules and name them: one point beyond 3 sigma; eight consecutive points on one side of the centre line; six points steadily increasing or decreasing; two of three consecutive points beyond 2 sigma on the same side; four of five beyond 1 sigma on the same side. Say that each extra rule raises the false-alarm rate, and recommend the first two or three for routine monitoring.
- Interpret: is the process stable (only common-cause variation) or are there special causes? For each signal, give the date, the rule and the questions to ask about what happened then. If stable, say what the limits predict for future performance and that improving it needs a change to the system, not a reaction to individual points.
- Provide code to compute and plot the chart in Python (pandas and matplotlib), with the centre line, limits and flagged points.
Limits
Table: Chart | Centre line | Lower limit | Upper limit | Working. One row per chart (for example I and MR).
Signals
Table: Point or date | Value | Rule triggered | Questions to investigate. Write "No signals" if none.
Interpretation
One short paragraph on stability and what to do next.
Code
One Python code block.