westernElectricRules

Applies the Western Electric Rules to the given observations to detect non-random patterns on a control chart.

The Western Electric Rules (WER), also known as the WECO rules, are a classical set of four heuristics that extend a Shewhart chart such as xBarRChart or xBarSChart beyond the basic 3σ limit check. They detect small, sustained shifts and clusters that a 3σ chart would miss — a drift of roughly 1σ–2σ is typically caught within a handful of observations. WER is often used alongside cusum and ewma charts, which are also tuned for small shifts.

The four rules are:

  • Rule 1 — any single point strictly beyond ±3σ from the center line.

  • Rule 2 — 2 out of 3 consecutive points strictly beyond ±2σ on the same side.

  • Rule 3 — 4 out of 5 consecutive points strictly beyond ±1σ on the same side.

  • Rule 4 — 8 consecutive points strictly on the same side of the center line.

Each rule is evaluated at every index i with enough preceding observations to form the pattern window (none for rule 1, i ≥ 2 for rule 2, i ≥ 4 for rule 3, i ≥ 7 for rule 4). The index stored in the result is the trigger point — the observation whose arrival completes the pattern. An observation may fire multiple rules at once, so the returned arrays can overlap.

All thresholds use strict inequalities, so a point that lands exactly on a sigma boundary does not count as a violation. NaN values in the data propagate through the comparisons (IEEE 754 semantics) — a NaN observation neither counts as "beyond" a limit nor as being on either side of the center, so it silently disqualifies any window that contains it.

Example:

val observations = doubleArrayOf(25.0, 24.5, 25.2, 26.1, 25.8, 27.0, 26.5, 28.0)
val violations = westernElectricRules(observations, center = 25.0, sigma = 1.0)
violations.rule1 // indices with a point beyond ±3σ
violations.rule2 // indices at which 2 of 3 points are beyond ±2σ on the same side
violations.rule3 // indices at which 4 of 5 points are beyond ±1σ on the same side
violations.rule4 // indices at which 8 consecutive points sit on the same side of the center

References: Western Electric Company, "Statistical Quality Control Handbook" (1956); Montgomery, "Introduction to Statistical Quality Control" (7th ed.), §5.4.

Return

a WesternElectricRulesResult with the trigger indices for each of the four rules.

Parameters

observations

the sequence of individual measurements to scan. Must contain at least 1 element.

center

the center line of the control chart, typically the in-control process mean. Any finite value is allowed.

sigma

the in-control process standard deviation σ. Must be strictly positive.

See also


Applies the Western Electric Rules to an Iterable of observations to detect non-random patterns on a control chart.

See the DoubleArray overload of westernElectricRules for the full description of the four rules, their trigger semantics, and the references.

Example:

val observations: List<Double> = listOf(25.0, 24.5, 25.2, 26.1, 25.8, 27.0, 26.5, 28.0)
val violations = westernElectricRules(observations, center = 25.0, sigma = 1.0)
violations.rule3 // indices at which 4 of 5 points are beyond ±1σ on the same side

Return

a WesternElectricRulesResult with the trigger indices for each of the four rules.

Parameters

observations

the sequence of individual measurements to scan. Must contain at least 1 element.

center

the center line of the control chart, typically the in-control process mean.

sigma

the in-control process standard deviation σ. Must be strictly positive.

See also


Applies the Western Electric Rules to a Sequence of observations to detect non-random patterns on a control chart.

See the DoubleArray overload of westernElectricRules for the full description of the four rules, their trigger semantics, and the references.

Example:

val observations: Sequence<Double> = sequenceOf(25.0, 24.5, 25.2, 26.1, 25.8, 27.0, 26.5, 28.0)
val violations = westernElectricRules(observations, center = 25.0, sigma = 1.0)
violations.rule3 // indices at which 4 of 5 points are beyond ±1σ on the same side

Return

a WesternElectricRulesResult with the trigger indices for each of the four rules.

Parameters

observations

the sequence of individual measurements to scan. Must contain at least 1 element.

center

the center line of the control chart, typically the in-control process mean.

sigma

the in-control process standard deviation σ. Must be strictly positive.

See also