Rule Evaluation
Run rules (also called detection rules or sensitising rules) extend the basic 3-sigma criterion by examining patterns of consecutive plotted points. A Shewhart chart with only the 3-sigma rule detects large, sudden process upsets reliably but may take many samples to detect smaller, sustained shifts. Run rules add sensitivity to systematic patterns that are statistically improbable under common-cause variation.
The Numerics.NET SPC library supports the Nelson rule set (rules N1–N8), the Western Electric rule set, and three additional predefined rule sets. All are applied through the ControlRuleSet type using IProcessRule instances, and return results as RuleSetEvaluation objects. Pre-built rule sets are available as static properties on ControlRuleSets.
Nelson rules N1–N8
The eight Nelson rules are the most widely adopted run-rule set in industry and quality standards. The table below gives the rule ID (as returned in RuleId), the historical name, the exact criterion, the minimum window length, and the intended signal type for each rule.
Rule ID / Historical name | Criterion | Window length | Signal type |
|---|---|---|---|
(N1 / WE1) | One point strictly beyond the ±3σ control limits (i.e. the plotted value is greater than UCL or less than LCL). | 1 | Large sudden shift or outlier |
(N2 / WE4 with run length 9) | 9 consecutive points all on the same side of the center line. | 9 | Sustained mean shift |
ConsecutiveIncreasingOrDecreasing (N3) | 6 consecutive points steadily increasing or steadily decreasing (each point strictly greater than or strictly less than the preceding point). | 6 | Trend / drift |
(N4) | 14 consecutive points alternating up and down (each point alternates direction from its predecessor). | 14 | Systematic alternation, often caused by two interleaved processes or over-adjustment |
TwoOfThreeBeyondTwoSigmaSameSide (N5 / WE3) | 2 out of 3 consecutive points beyond the ±2σ zone on the same side of the center line. | 3 | Moderate sustained shift |
FourOfFiveBeyondOneSigmaSameSide (N6 / WE4) | 4 out of 5 consecutive points beyond the ±1σ zone on the same side of the center line. | 5 | Small sustained shift |
(N7) | 15 consecutive points all within the ±1σ zone (above or below the center line, on either side). | 15 | Stratification — data appear artificially clustered near the center, often caused by incorrect subgrouping or mixing two populations |
(N8) | 8 consecutive points all outside the ±1σ zone (on either side of the center line). | 8 | Mixture — data cluster near the control limits, often caused by sampling from two different populations |
The sigma zones referenced in the table (±1σ, ±2σ, ±3σ) are computed relative to the chart's own within-process sigma estimate. For the Individuals chart, this is the sigma derived from the moving range. For XBar charts, this is the sigma of the subgroup means (not the process sigma).
Predefined rule sets
The ControlRuleSets class provides five ready-to-use rule sets as static properties:
- ControlRuleSets.Nelson
Applies all eight Nelson rules (N1–N8). This is the most comprehensive rule set and is appropriate for general-purpose monitoring of variables charts (Individuals, XBar-R, XBar-S).
- ControlRuleSets.WesternElectric
Applies the four original Western Electric Handbook rules: PointBeyondControlLimits (N1/WE1), TwoOfThreeBeyondTwoSigmaSameSide (N5/WE3), FourOfFiveBeyondOneSigmaSameSide (N6/WE4), and ConsecutivePointsOnSameSide with run length 8 (WE4, shorter than Nelson's 9). These are a subset of the Nelson rules and were historically used in the telephone manufacturing industry.
- ControlRuleSets.AttributeConservative
Applies only PointBeyondControlLimits and ConsecutivePointsOnSameSide (run length 9). Appropriate for attribute charts (P, NP, C, U) where zone rules produce excessive false alarms due to non-normality.
- ControlRuleSets.HealthcareIHI
Applies three rules following IHI guidance: PointBeyondControlLimits, ConsecutivePointsOnSameSide with run length 8, and ConsecutiveIncreasingOrDecreasing with run length 6. Intended for healthcare quality-improvement Shewhart charts.
- ControlRuleSets.BasicShewhart
Applies only PointBeyondControlLimits. This is the recommended rule set for EWMA and CUSUM chart statistics, which are serially correlated and therefore not suitable for run rules.
You can also construct a custom ControlRuleSet that includes only the rules relevant to your process, reducing the false-alarm rate when certain patterns are known to be impossible in your context.
// Create a custom rule using a delegate
var customRule = new CustomRule(
"NearCenterLine",
"Many consecutive points near the center line",
ctx =>
{
// Detect 10+ consecutive points within 0.5σ of center line.
// Sigma-zone helpers require SupportsSigmaZones; return empty
// for pointwise-limit series such as P/U charts and EWMA.
if (!ctx.SupportsSigmaZones)
return [];
var violations = new List<RuleViolation>();
int run = 0;
for (int i = 0; i < ctx.PointCount; i++)
{
// IsBeyondSigma(strict: false) is true when |pt - CL| >= 0.5σ,
// so its negation captures the "within 0.5σ" condition.
if (!ctx.IsBeyondSigma(i, 0.5, strict: false))
{
run++;
if (run >= 10)
violations.Add(new RuleViolation(
i, "NearCenterLine",
"10+ consecutive points near the center line",
i - 9, 10));
}
else
{
run = 0;
}
}
return violations;
});
// Compose with built-in rules
var ruleSet = new ControlRuleSet("Custom", new IProcessRule[]
{
ProcessRules.PointBeyondControlLimits,
ProcessRules.ConsecutivePointsOnSameSide(9),
customRule
});
// Apply the custom rule set to a chart
double[] data = {
10.5, 11.2, 10.8, 11.5, 10.3, 11.8, 10.1, 11.4,
10.9, 11.1, 10.6, 11.3, 10.7, 11.0, 10.4
};
IndividualsMovingRangeChartSet chart =
new IndividualsMovingRangeChartSet(Vector.Create(data));
chart.Analyze();
RuleSetEvaluation result = chart.IndividualsSeries.EvaluateRules(ruleSet);
Console.WriteLine($"Custom rule violations: {result.Violations.Count}");Rule evaluation result structure
Calling Evaluate(RuleEvaluationContext) on a ControlRuleSet returns a RuleSetEvaluation. The most important members are:
Property | Description |
|---|---|
a bool that is true if at least one rule fired anywhere in the series. Use this for a quick pass/fail stability decision. | |
The canonical, deterministically ordered list of RuleViolation objects describing every individual firing. Violations are ordered by TriggerIndex ascending; ties are broken by RuleId in ordinal order. | |
The name of the ControlRuleSet used for evaluation, matching the Name property of the rule set. May be null for anonymous rule sets. | |
A derived map from each point index to all violations whose windows include that index. Covers all window indices, not just trigger points. Computed lazily on first access. |
RuleViolation properties
Each RuleViolation has the following properties:
- TriggerIndex
The zero-based index of the trigger point — the observation at which the rule became true. For point rules (PointBeyondControlLimits), this equals WindowStart. For pattern rules, this is the last point in the pattern (WindowStart + WindowLength - 1). Violations are uniquely identified by the combination of (RuleId, TriggerIndex).
- RuleId
The stable programmatic identifier for the rule family. Use this to programmatically distinguish rule types, for example when filtering to show only certain categories in a UI. Canonical values include PointBeyondControlLimits, ConsecutivePointsOnSameSide, ConsecutiveIncreasingOrDecreasing, AlternatingUpDown, TwoOfThreeBeyondTwoSigmaSameSide, FourOfFiveBeyondOneSigmaSameSide, FifteenWithinOneSigma, and EightOutsideOneSigma.
- RuleName
The user-facing display name of the rule, suitable for display in a tooltip or status message.
- WindowStart
The zero-based index of the first observation in the window that contributed to the violation. For PointBeyondControlLimits, this equals TriggerIndex. For pattern rules, this is TriggerIndex - WindowLength + 1.
- WindowLength
The number of consecutive observations in the window. For PointBeyondControlLimits this is 1; for ConsecutivePointsOnSameSide(9) it is 9; for ConsecutiveIncreasingOrDecreasing(6) it is 6; and so on. For TwoOfThreeBeyondTwoSigmaSameSide and FourOfFiveBeyondOneSigmaSameSide, the window length is the full candidate window (3 and 5 respectively), even though only 2 of 3 or 4 of 5 points need satisfy the criterion.
Rendering violation windows on a chart
The WindowStart and WindowLength properties are designed to support visual highlighting of violation regions. The window covers the observations at indices WindowStart through WindowStart + WindowLength - 1 inclusive.
For per-point rendering, use ViolationsByIndex to look up all violations whose windows include a given index. This covers all window positions, not just the TriggerIndex.
Recommended rendering approach:
Draw the background of the chart normally.
For each violation, shade or highlight the chart region from the x-position of WindowStart to the x-position of WindowStart + WindowLength - 1 using a semi-transparent colour. Different rule types can use different colours to convey meaning at a glance.
Mark the trigger point (TriggerIndex) with a distinct marker (e.g. a filled circle or a triangle) to draw the analyst's attention to the confirming observation.
Include the RuleName in a tooltip or annotation attached to the trigger point marker.
Multiple violations can overlap. A single observation may appear in the windows of several rules simultaneously, particularly when a real process shift triggers both a location rule (N2) and a sigma rule (N6). Render all overlapping windows; do not suppress later violations because earlier ones cover the same region.
The following code example demonstrates evaluating rules and extracting violation windows:
double[] data = {
10.5, 11.2, 10.8, 11.5, 10.3, 11.8, 10.1, 11.4,
10.9, 11.1, 10.6, 11.3, 10.7, 11.0, 10.4
};
IndividualsMovingRangeChartSet chart =
new IndividualsMovingRangeChartSet(Vector.Create(data));
chart.Analyze();
RuleSetEvaluation ruleResult =
chart.IndividualsSeries.EvaluateRules(ControlRuleSets.Nelson);
Console.WriteLine($"Violations: {ruleResult.Violations.Count}");
foreach (RuleViolation v in ruleResult.Violations)
Console.WriteLine(
$" {v.RuleId}: {v.RuleName} at index {v.TriggerIndex}");The following code example demonstrates mapping violation windows to chart highlight regions:
double[] data = {
10.5, 11.2, 10.8, 11.5, 10.3, 11.8, 10.1, 11.4,
10.9, 11.1, 10.6, 11.3, 10.7, 11.0, 10.4
};
IndividualsMovingRangeChartSet chart =
new IndividualsMovingRangeChartSet(Vector.Create(data));
chart.Analyze();
RuleSetEvaluation ruleResult =
chart.IndividualsSeries.EvaluateRules(ControlRuleSets.Nelson);
foreach (RuleViolation v in ruleResult.Violations)
{
int windowEnd = v.WindowStart + v.WindowLength - 1;
// Shade the supporting window in your rendering layer
Console.WriteLine(
$"Shade {v.WindowStart}..{windowEnd} for rule {v.RuleId}");
}Signals vs. root causes
A rule violation is a statistical signal, not a confirmed root cause. It means that the observed pattern is sufficiently unlikely under the assumption of a stable, common-cause process to warrant investigation. The interpretation depends on context:
PointBeyondControlLimits (N1) typically indicates a sudden upset: a bad batch, equipment failure, measurement error, or a genuinely exceptional unit.
ConsecutivePointsOnSameSide (N2), FourOfFiveBeyondOneSigmaSameSide (N6) typically indicate a sustained mean shift: a process adjustment, a new supplier lot, a temperature change.
ConsecutiveIncreasingOrDecreasing (N3) indicates a trend: tool wear, reagent depletion, gradual temperature drift, operator fatigue.
AlternatingUpDown (N4) typically indicates two interleaved sub-processes (e.g. two spindles, two cavities) that have different means, or an operator who alternately over-corrects and under-corrects.
FifteenWithinOneSigma (N7) (stratification) suggests the subgroups contain data from multiple populations that are being averaged together, masking real between-subgroup variation.
EightOutsideOneSigma (N8) (mixture) suggests sampling from two populations with different means in alternation, so that the center line falls in the gap between them.
Multiple overlapping violations do not indicate more severe problems; they indicate that the same process anomaly is detectable by more than one pattern-recognition criterion simultaneously, which is expected when a real shift occurs.
Run rules apply only to Shewhart chart statistics
Run rules are appropriate for the Individuals chart, the XBar chart, and the subgroup Range or Standard Deviation charts — all of which produce approximately independent observations under an in-control process.