Python and Process Control — Part 1
Control Charts
Simply put, control charts are used to diagnose and then monitor a process. Originally designed for manufacturing environments, they are capable of providing insight into any process with measurable outputs in a variety of industries (you don’t have to manufacture widgets in a production facility to benefit from control charts).
The charts used depend on the datatype and subgroup size however they all display useful information regarding how a process changes over time. Initially we’ll be focusing on charts that use continuous data and are typically used in pairs. Here’s a list of those chart types and their subgroup requirements:
- Individuals-Moving Range (I-MR)
- no subgroups, individual samples/measurements - Xbar-Range (Xbar-R)
- subgroups of 2 to 9 samples/measurements - Xbar-Standard Deviation (Xbar-S)
- subgroups of 10 samples/measurements or more
Python
“Control Charts sound cool Bob, but what why Python!?”
There are plenty of companies that sell software packages that will “do it all” for you. But I like to break things down and build them back up to ensure I’m grasping the concepts and theory surrounding a given topic.
Enter Python.
Essentially free (you’ll need a computer), Python just requires some know-how and a little time. In the example below I used the Jupyter Notebook IDE with Python 3.7.4.
Control Chart Components
Control charts plot data in time order with reference lines calculated from historical data for the Mean and Upper/Lower Control Limits (UCL/LCL respectively). The Mean, the central green line in the chart above, is the average of the data measurements when establishing the process and serves as a baseline to compare future measurements against. The red UCL and LCL lines are calculated by either adding 3*𝜎 to (UCL) or subtracting 3*𝜎 from (LCL) the process mean (where 𝜎 = the historical standard deviation).
Comparing current data to these key values we can determine whether variation is common cause (inherent to the process) or special cause (equipment component wearing down, incorrect set point(s), gaps in training, not correctly following a procedure or recording data, etc).
Control Chart Rules
“If it ain’t broke, don’t fix it.”
When properly maintained, a process is most efficient when setup correctly and with as little interference as possible. There are multiple rules that can be applied to the data points as they’re plotted on the chart that alert the user to the occurrence of significant events or an “out of control” process. As we continue this series we’ll cover these rules and add in messages for rule violations.
First up: Xbar Chart
Xbar charts are used for variables with continuous data collected from sample subgroups, plotting the average value of the subgroup against the historical mean and control limits. Below, I’ll lay out the steps for creating a basic Xbar chart. We’ll cover additional chart options to handle a variety of sampling scenarios and data types in the future.
Our Example
Let’s say we have a new high-tech production line that makes widgets 24 hours a day, 7 days a week. On a regular schedule each shift, 12 widgets are collected from the production line by the quality assurance tech and measured for width.
Let’s import the Python libraries we’ll need:
Now let’s create a function to generate datasets based on a few parameters:
Here we’ll notionally establish our process conditions and generate our Mean and Standard Deviation values. To do this we gathered 100 groups of widgets with 12 widgets in each group. The process is setup to meet a target of 97mm.
Now we have a dataset where the process mean for width is 96.986mm and the standard deviation is 0.885. Let’s create a sample dataset and see how our process looks.
Looking good!
Now, let’s say it’s shift change and the new operator makes a seemingly negligible adjustment to the equipment. How will the chart look? Here’s a second sample dataset, centering on 99.5 instead of our original 97, appended to the original.
Well that’s a problem! Even without discussing the control chart rules we can see that something has changed in the process and we’re not functioning as expected. From this chart we can easily go back to the information regarding the production of samples 23 and 24 to determine what changed. As we introduce the control chart rules we’ll see that we would’ve been alerted to this situation much sooner than sample 35.
That’s it! For now…
Thanks for reading my article. Check back soon for additional content and more on Control Charts!
Looking Forward
- The Individuals Chart: examples for when this chart type should be used and how it compares to the Xbar Chart.
- Moving Range, Range, and Standard Deviation charts: why are these just as important and used in tandem with I and Xbar charts?
- Chart types for attribute/categorical data.