A bug is a nonconforming unit or imperfection that causes a product to fail a specified quality criterion. Quality control represents bugs either as defective items or as counted defects. section 14.1.7 section 14.1.8
Choose the control-chart representation according to what must be monitored:
- Use a p-chart to track the proportion of defective items in successive samples and detect trends, shifts, or unusual process behavior. section 14.2.1
- Use an np-chart to track the number of defective items when every sample has the same size. section 14.2.2
- Use a c-chart to count multiple defects within each unit or sample, such as scratches, dents, or misalignments. section 14.1.8
- Use a u-chart to normalize defect counts by inspected units when sample sizes vary. section 14.1.8
Monitoring orange-juice batches
A dataset records defective cans across 64 batches. For each batch, calculate proportion defective as D divided by sample size, compute the mean proportion, estimate sigma, and draw limits at the mean plus or minus three sigma. Points beyond the limits indicate potential process issues requiring investigation. With a constant sample size of 50, an np-chart instead plots D directly; using two-standard-deviation limits highlights a pair of points above the upper control limit. section 14.2.1 section 14.2.2
>>> oj['proportion'] = oj['D'] / oj['size']
Compute each sample's defective proportion before estimating the p-chart center line and control limits. section 14.2.1
>>> np_bar = oj['D'].mean() #1
>>> UCL_np = np_bar + 2 * np.sqrt(np_bar) #2
>>> LCL_np = np_bar - 2 * np.sqrt(np_bar) #3
>>> plt.figure() #4
>>> plt.plot(oj['sample'], oj['D'],
>>> marker = 'o',
>>> linestyle = '-',
>>> label = 'Number of Defective Items') #5
>>> out_of_control = \
>>> (oj['D'] > UCL_np) | (oj['D'] < LCL_np) #6
>>> plt.plot(oj['sample'][out_of_control],
>>> oj['D'][out_of_control],
>>> marker = 'o', color = 'r', linestyle = 'None',
>>> label = 'Out of Control') #7
>>> plt.axhline(y = np_bar,
>>> color = 'r', linestyle = '--',
>>> label = 'np-bar (Mean)') #8
>>> plt.axhline(y = UCL_np,
>>> color = 'g', linestyle = '--',
>>> label = 'UCL') #9
>>> plt.axhline(y = LCL_np,
>>> color = 'g', linestyle = '--',
>>> label = 'LCL') #10
>>> plt.fill_between(oj['sample'],
>>> LCL_np, UCL_np,
>>> color = 'g', alpha = 0.1) #11
>>> plt.title('np-Chart') #12
>>> plt.xlabel('Sample') #13
>>> plt.ylabel('Number of Defective Items') #14
>>> plt.legend(loc = 'upper left',
>>> bbox_to_anchor = (0.1, 0.9)) #15
>>> plt.grid(True) #16
>>> plt.show() #17
Calculate np-chart limits, identify out-of-control counts, and highlight those observations in Matplotlib. section 14.2.2


