liveBook · Manning

Bug

As explained in Statistics Every Programmer Needs

A defect is an imperfection or nonconformity that causes a product or unit to fail a specified quality criterion.

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

How Statistics Every Programmer Needs covers it

How deep it goes
Demonstrates definitions, chart selection, control-limit calculations, Python implementation, visualization, and interpretation of out-of-control points.
Examples
Uses orange-juice can batches containing physical damage, sealing, labeling, corrosion, and contamination examples.
What it assumes
Assumes categorical quality observations and introduces defective-item counts, defect counts, sample proportions, means, and control limits.
What you can do after
Diagnose/debug with it by selecting an attribute chart, calculating control limits, plotting defects, and investigating unusual observations.
How it connects
Connects defective items and defect counts with p-charts, np-charts, c-charts, u-charts, control limits, mean, and standard deviation.

Also explained in

Compare how 3 books explain bug →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.