|
Product |
Version |
| Spotfire |
All Supported Versions |
Keywords:
Nelson Rules, Statistical Process Control, SPC, Rule 2, Rule 3, Python, Spotfire, Dashboard, Violation Analysis, Control Limits.
Introduction: This article explains how to implement Nelson Rules 2 and 3 for statistical process control (SPC) using Python and visualize the results in a Spotfire dashboard. The solution helps identify violations of control limits in datasets, enabling better process monitoring and quality control.
Overview: Nelson Rules are a set of eight rules used in SPC to detect out-of-control processes. This article focuses on:
- Rule 2: Two consecutive points outside the control limits (UCL or LCL).
- Rule 3: Four out of five consecutive points beyond one standard deviation from the mean.
The solution uses Python to calculate violations and Spotfire to visualize the results with color-coded tables and summary graphs.
Solution:
-
1. Python Script for Nelson Rules Analysis
Code:
import numpy as np import pandas as pd def check_nelson_rules(cqa, ucl, lcl): """ Check Nelson Rules 2 and 3, returning violation flags. """ cqa = np.array(cqa) rule2 = np.zeros_like(cqa, dtype=bool) rule3 = np.zeros_like(cqa, dtype=bool) # Rule 2: Two consecutive points outside control limits for i in range(len(cqa) - 1): if (cqa[i] ucl and cqa[i+1] ucl) or (cqa[i] <lcl): rule2[i]="True" rule2[i+1]="True" #="#" rule="Rule" 3:="3:" four="Four" out="out" of="of" five="five" consecutive="consecutive" points="points" beyond="beyond" limits="limits" for="for" i="i" in="in" range(len(cqa)="range(len(cqa)" -="-" 4):="4):" window="cqa[i:i+5]" above="window"> ucl below = window = 4: rule3[i:i+5] |= above if np.sum(below) = 4: rule3[i:i+5] |= below return rule2, rule3 # Example usage data = {'Column1': [10,12,14,13,15,18,20,25,30,28], 'Column2': [25,26,24,23,22,20,19,18,17,16]} df = pd.DataFrame(data) UCL = 24 LCL = 8 # Create violation flags for each column combined_df = df.copy() for col in df.columns: r2, r3 = check_nelson_rules(df[col].values, UCL, LCL) combined_df[f"{col}_N2"] = r2 # Rule 2 flags combined_df[f"{col}_N3"] = r3 # Rule 3 flags # Output the combined table Output = combined_dfOutput:
- A single table with original data and appended violation flags (
_N2for Rule 2 and_N3for Rule 3). - Flags are
Trueif a violation occurs andFalseotherwise.
- A single table with original data and appended violation flags (
-
2. Spotfire Dashboard
Features:
-
Table Visualization: Violating cells are color-coded:
- Red for Rule 2 violations.
- Gold for Rule 3 violations.
- Graph Table: Summarizes the number of violations per column.
Attached Dashboard:
Sample_Nelson_Rules_Analysis.dxp -
Table Visualization: Violating cells are color-coded:
Nelson Rules Concept:
- Rule 2: Detects shifts in the process mean by identifying two consecutive points outside the control limits.
- Rule 3: Detects trends by identifying four out of five consecutive points beyond one standard deviation from the mean.
References:
Conclusion: This solution provides an easy way to implement Nelson Rules 2 and 3 using Python and visualize the results in Spotfire. The attached dashboard demonstrates how to identify and analyze violations effectively.
Comments
0 comments
Please sign in to leave a comment.