Detecting Subtle Process Shifts
A bearing temperature reads 52°C. Then 52.1. Then 52.2. Each reading is within its alarm limits. No single point looks wrong. But the process is creeping upward — and over dozens of samples, the last eight readings have all landed above the long-term average. A pattern that should happen less than 0.4% of the time in a stable process.
This recipe uses esStats to compute a z-score for each sample, a passIf gate to skip the warmup period, and four persistenceCheck nodes to evaluate the classic Western Electric rules against that z-score. No median3 — run rules must see isolated spikes, not smooth them away.
flow( 'run-rules' )
.sanitize( 'sane', 'measurement', { failureReason: 'failReason' },
{ ranges: { measurement: { min: 0, max: 100 } } } )
.esStats( 'stats', 'measurement',
{ mean: 'mean', stdev: 'sigma', zScore: 'zScore' },
{ halfLife: 30 } )
.passIf( 'warmup', ( msg, counter ) => counter > 60 )
.persistenceCheck( 'rule1',
( msg ) => msg.zScore > 3,
{ persistenceConfirmed: 'beyond3sigma' },
{ minVotes: 1, outOfTotal: 1 } )
.persistenceCheck( 'rule2',
( msg ) => msg.zScore > 2,
{ persistenceConfirmed: 'twoOfThree' },
{ minVotes: 2, outOfTotal: 3 } )
.persistenceCheck( 'rule3',
( msg ) => msg.zScore > 1,
{ persistenceConfirmed: 'fourOfFive' },
{ minVotes: 4, outOfTotal: 5 } )
.persistenceCheck( 'rule4',
( msg ) => msg.zScore > 0,
{ persistenceConfirmed: 'eightSameSide' },
{ minVotes: 8, outOfTotal: 8 } )
.run()Drag the slider and watch the rules fire in sequence as the deviation grows.
What You’re Seeing
The gray line is the raw process measurement — noisy readings around 50. The cyan line is the exponentially smoothed mean (halfLife=30), tracking the underlying process level. The faded cyan band marks the ±3σ control limits.
The violet dashed curve on the right axis is the z-score — how many standard deviations each sample deviates from the baseline.
At sample 80, an isolated spike pushes the measurement well above the upper control limit. The z-score jumps past 5, and Rule 1 fires immediately — the first rose marker. Because there is no median3 in this pipeline, the spike reaches the rules unfiltered.
After sample 100, the process mean begins creeping upward. As the deviation grows, the rules fire in sequence: Rule 2 catches early noise peaks that push past 2σ. Rule 4 fires when eight consecutive readings land above center — sustained bias that random noise cannot explain. Rule 3 fires last, once the deviation has grown large enough that four of five readings consistently exceed 1σ.
Where This Pattern Fits
| Domain | What shifts | Why threshold alarms miss it |
|---|---|---|
| Pharmaceutical manufacturing | Tablet press fill weight after blade change | New blade shifts mean by 0.5% — within spec, but yield drops |
| Semiconductor fabrication | Etch depth after chamber clean | 0.3 nm offset — no single wafer fails, batch yield declines |
| Automotive assembly | Torque setting across operator shifts | New operator shifts mean by 2 Nm — within tolerance |
| Dairy processing | Pasteurization temperature after CIP cycle | Thermocouple reseats 0.3°C lower — readings look normal |
| Water treatment | pH after reagent batch change | New reagent lot shifts reading by 0.1 — compliance alarm is ±0.5 |
How It Works
No Median3
Unlike the drift and freeze recipes, this pipeline omits median3. The median filter smooths transient spikes — exactly the events Rule 1 is designed to catch. Including it would defeat the purpose.
Z-Score as the Detection Signal
The esStats node maintains exponentially smoothed estimates of the mean and standard deviation. For each incoming sample, it computes a z-score before updating the estimates — measuring how surprising the new value is relative to what the process has been producing, not what it is producing now. This preserves detection semantics: the baseline does not absorb the deviation before the rules notice it.
A halfLife of 30 means that samples 30 readings ago carry half the weight of the current one. Short enough for a responsive baseline; long enough that the mean lags behind a growing deviation, keeping z-scores elevated.
Warmup Gate
A passIf node blocks the first 60 messages — giving esStats time to converge before the run rules begin evaluating. The gate sits between esStats and the rules: esStats receives every sample (building its baseline), but the rules only see messages after the baseline stabilizes. Without this gate, erratic early z-scores produce false detections.
The Four Rules
| Rule | What it detects | persistenceCheck | Sensitivity |
|---|---|---|---|
| Rule 1 | Isolated spike | 1-of-1 beyond 3σ | Lowest — catches only large excursions |
| Rule 2 | Repeated exceedance | 2-of-3 beyond 2σ | Moderate — needs consistent deviation |
| Rule 3 | Sustained bias | 4-of-5 beyond 1σ | High — catches subtle shifts |
| Rule 4 | Process bias | 8-of-8 same side | High — catches any persistent asymmetry |
Each persistenceCheck maintains a sliding vote window. It evaluates its predicate on each message, records a vote (true or false), and confirms when the minimum threshold is reached within the window. When confirmed — or when confirmation becomes mathematically impossible — the window auto-resets for the next detection.
One-Sided Detection
The predicates check the positive direction only (msg.zScore > 1,
not Math.abs( msg.zScore ) > 1). This halves the false alarm rate
compared to two-sided checking, and matches the classical Western
Electric formulation: each rule is evaluated separately on each side
of center. For below-center detection, add a parallel set of rules
with msg.zScore < 0, msg.zScore < -1, msg.zScore < -2, and
msg.zScore < -3.
Progressive Sensitivity
The rules form an early warning cascade. As a process deviation grows, the rules fire in order of what they can see: Rule 2 catches the first noise peaks that exceed 2σ. Rule 4 detects sustained bias. Rule 3 confirms once the deviation is large enough that most readings consistently exceed 1σ. Rule 1 catches isolated excursions that the pattern rules miss entirely.
References
- Western Electric Company (1956). Statistical Quality Control Handbook. AT&T Technologies, Indianapolis.
- Montgomery, D.C. (2019). Introduction to Statistical Quality Control, 8th ed. Wiley. ISBN 978-1-119-39930-8
- Wheeler, D.J. (2000). Understanding Variation: The Key to Managing Chaos, 2nd ed. SPC Press.
Next Steps
- Detecting Gradual Drift — the complementary recipe for slow, continuous drift using fast/slow esMean crossover
- Detecting Sudden Shifts — abrupt step changes detected by Kalman innovation gating
- Detecting Sensor Freeze — detect when a sensor stops changing using running standard deviation collapse
- Under the Hood — understand what happens inside the pipeline