Use a declared baseline and period-specific limits for binomial proportions, then investigate signals without inventing causes.
P charts: account for varying denominators before flagging a rate
A rate needs its opportunity count
A p chart follows a proportion such as defective shipments divided by inspected shipments. Forty-seven defects in 470 inspections and 47 in 4,700 do not carry the same sampling uncertainty. Plot the period denominator or put it in a table, and calculate limits from the baseline proportion using each period's sample size. Denominator discipline is the first check. Do not mix units such as orders and line items, or change the defect definition midway through the series.
Freeze the baseline before judging a new point
Choose a stable historical interval and document excluded outages, policy changes and incomplete periods. Pool baseline defects over baseline opportunities for a center line. Calculating a fresh center from every newly flagged point can move the goalposts. A period beyond an approximate three-standard-error limit is a signal to investigate; it does not prove a specific cause. Event annotations should distinguish observed timing from causal evidence. A confirmed process change may justify a new baseline, but record where the old phase ends.
Know the approximation's limits
The simple p-chart formula assumes independent, comparable Bernoulli opportunities and a fairly stable underlying probability. Correlated batches, rare events or extra variation can make the limits misleading. Tiny sample sizes produce wide limits; values must still stay between zero and one. If repeated points reveal more variation than the model allows, investigate the collection process or choose a method suited to overdispersion. Small-sample displays help communicate why a large-looking percentage swing may be weak evidence. A control limit is not a target or a confidence interval for a business decision.
Explain the chart without color
Show the center line, period-specific bounds, actual rate, numerator and denominator in the export. Mark flagged points with shape and text, not red alone. If a late-arriving batch changes a historical numerator, recompute the affected point and disclose the revision. Provisional periods should be clearly separate from finalized ones. An accessible summary can state which periods crossed limits and which lacked enough data, while leaving the causal diagnosis to the investigation.
Worked contract
from math import sqrt
def p_chart_rows(baseline: list[tuple[int, int]],
periods: list[tuple[str, int, int]]
) -> list[tuple[str, float, float, float, bool]]:
def valid(defects: int, inspected: int) -> bool:
return (isinstance(defects, int) and isinstance(inspected, int)
and inspected > 0 and 0 <= defects <= inspected)
if not baseline or any(not valid(d, n) for d, n in baseline):
raise ValueError("baseline requires valid defect counts")
if any(not label or not valid(d, n) for label, d, n in periods):
raise ValueError("period counts or labels are invalid")
center = sum(d for d, _ in baseline) / sum(n for _, n in baseline)
output = []
for label, defects, inspected in periods:
radius = 3 * sqrt(center * (1 - center) / inspected)
lower, upper = max(0.0, center - radius), min(1.0, center + radius)
rate = defects / inspected
output.append((label, rate, lower, upper, rate < lower or rate > upper))
return output
baseline = [(47, 470), (59, 590), (81, 810)]
signals = p_chart_rows(baseline, [("week-47", 47, 470),
("week-48", 3, 470)])
assert round(signals[0][1], 4) == 0.1
assert signals[1][-1] is TruePerformance and operating cost
For B baseline periods and P plotted periods, this calculation takes O(B+P) time and O(P) output space. The three-standard-error limits are an approximation under an independent binomial model; the code does not test independence, estimate overdispersion or infer a cause. A production pipeline should version the baseline and defect definition, enforce finalized counts, and show denominator size with every point.
Common Mistakes
- Comparing percentages while concealing sharply different sample sizes.
- Recomputing the baseline after every flagged period.
- Calling a control limit a business target.
- Treating a signal as proof of the annotated event's effect.
Validation drill
Track 59 weekly inspection proportions with variable sample sizes. Freeze a baseline, flag points beyond their own limits and investigate a week whose rate is high but denominator is small.
Read next
- Aggregation grain and denominator: make every plotted mark auditable
- Uncertainty on charts: show denominators and intervals beside estimates
- Time-series charts: distinguish missing days, zeros and provisional periods
- Chart annotations: align events to the right clock without claiming causality
