 Content DisclaimerCopyright @2014.All Rights Reserved.
StatsToDo : CUSUM for Bernoulli Distributed Proportions Explained and R Code

Introduction Example R Code Example Explained
This page provides explanations and example R codes for CUSUM quality control charts, for detecting changes in proportions that conforms to the Bernoulli Distribution.

### CUSUM Generally

CUSUM is a set of statistical procedures used in quality control. CUSUM stands for Cumulative Sum of Deviations.

In any ongoing process, be it manufacture or delivery of services and products, once the process is established and running, the outcome should be stable and within defined limits near a benchmark. The situation is said to be In Control

When things go wrong, the outcomes depart from the defined benchmark. The situation is then said to be Out of Control

In some cases, things go catastrophically wrong, and the outcomes departure from the benchmark in a dramatic and obvious manner, so that investigation and remedy follows. For example, the gear in an engine may fracture, causing the machine to seize. An example in health care is the employment of an unqualified fraud as a surgeon, followed by sudden and massive increase in mortality and morbidity.

The detection of catastrophic departure from the benchmark is usually by the Shewhart Chart, not covered on this site. Usually, some statistically improbable outcome, such as two consecutive measurements outside 3 Standard Deviations, or 3 consecutive measurements outside 2 Standard Deviations, is used to trigger an alarm that all is not well.

In many instances however, the departures from outcome benchmark are gradual and small in scale, and these are difficult to detect. Examples of this are changes in size and shape of products caused by progressive wearing out of machinery parts, reduced success rates over time when experienced staff are gradually replaced by novices in a work team, increases in client complaints to a service department following a loss of adequate supervision.

CUSUM is a statistical process of sampling outcome, and summing departures from benchmarks. When the situation is in control, the departures caused by random variations cancel each other numerically. In the out of control situation, departures from benchmark tend to be unidirectional, so that the sum of departures accumulates until it becomes statistically identifiable.

The mathematical process for CUSUM is in 2 parts. The common part is the summation of depertures from the bench mark (CUSUM), and graphically demonstrating it. The unique part is the calculation of the decision interval abbreviated as DI or h, and the reference value, abbreviated as k, which continuously adjustes the CUSUM and its variance. The two values of h and k depend on the following parameters

• The in control values
• The out of control values
• The Type I Error or false positive rate, expressed as the Average Run Length, abbreviated as ARL, the number of samples expected for a false positve decision when the situation is in control. ARL is the inverse of false positive rate. A false positive rate of 1% would have ARL=100

### Proportions

Proportions can be handled under 3 common types of distribution
• The Binomial Distribution where the measurement is the number of the positive cases in a group of set sample size. The advantage of such an appropach is that the results tend to be stable, as short term variations are evened out with many cases. The disadvantage is that evaluation can only take place when the planned sample size per group has been reached, so conclusions tend to take a long time.
• The Negative Binomial Distribution Where the measurement is the number of negative cases between a set number of positive cases. Evaluation can take place after each time the set number of positive case is reached, so conclusions can be reached sooner. However the results tend to be more variable as it is influenced by short term variations.
• The Bernoulli Distribution where the measurement is either positive or negative for each case. Evaluation therefore takes place after each observation, so conclusions can be reached very quickly, but the results tend to be more chaotic as it varies with each observation.
• This page describes the Bernoulli Distribution. CUSUM for Binomial Distribution is discussed in the CUSUM for Binomial Distributed Proportion Explained Page, and that for Negative Binomial Distribution in CUSUM for Negative Binomial Distributed Counts Explained Page

### CUSUM for Proportions based on the Bernoulli Distribution

The Bernoulli Distribution is based on the probability of any individual observation to be positive (yes, +, TRUE, 1) or negative (no, -, FALSE, 0), and in the algorithm provided by StatsToDo these are represented by 0 and 1. An example is the monitoring of Caesarean Section rates in a maternity unit, where a case delivered normally is represented by 0 and that by Caesarean Section by 1.

The advantages of using the Bernoulli distribution for CUSUM is that the CUSUM value can be calculated with every case, based on whether the case is positive (1) or negative (0). It is therefore more responsive to changes as it does not have to wait for the collection of a group of cases before a proportion can be calculated.

The disadvantage of doing CUSUM using the Bernoulli distribution is that the model is highly sensitive to any change, so that short term variations may cause mark changes to CUSUM and trigger false alarms. An example is monitoring adverse surgical outcomes, when most of the dangerous operations are carried out on a particular day by a senior surgeon, so that the adverse outcomes peaks one day a week rather than being averaged over the whole week, causing a false alarm to be triggered

As I cannot find an easily usuable existing algorithm for CUSUM using Bernoulli distribution in the R archive CRAN, I developed a program based on the algorithm described in the paper by Reynolds and Stoumbos (see references). I have adopted the same terminology used in the paper, which are similar but different to the other CUSUM programs on StatsToDo.

The input parameters are:

• The Proportion in control (inControlProp), between 0 and 1 so that 0.2 means 20%
• The Proportion out of control (outOfControlProp).
• The Average Number of Observations (ANOS), the same concept as Average Run Length (ARL) in other CUSUM programs, the expected average number of cases between false alarms
• The Data (dat) is a vector (array) of values, with 0 representing negative and 1 positive
The algorithm calculates the same statistical parameters as other CUSUMs, but again uses names from the paper
• The Reference Value, (γB or gb) is equivalent to k in other CUSUM programs, except that it is used differently to construct the CUSUM.
• The Decision Interval, h, is the same as in other CUSUM models, used to trigger an alarm

### References

Reynolds Jr. MR and Stoumbos ZG (1999) A CUSUM Chart for Monitoring a Proportion when Inspecting Continuously. Journal of Quality Technology vol 31: No. 1. p.87 - 108