Plot a Cumulative Sum Quality Control Chart

DESCRIPTION:
Plots a cumulative sum chart based on a "qcc" object and optional within group standard deviation, decision interval sizes, reference value, rules, and fast initial response value.

SIMPLE:
cusum(object, newdata)

USAGE:
cusum(object, newdata, type, z.scores, decision.int = 5, se.shift = 1,
      target, std.dev, sizes, labels, label.bounds = c("LDB","UDB"),
      headstart = decision.int/2, reset = F, add.stats = T,
      chart.all = F, ylim.min = NULL, check.cl = F,
      highlight = list(pch=1, col=2))

REQUIRED ARGUMENTS:
object:
an object of class "qcc" which provides information on the type of group summary statistics to compute and the within group standard deviation necessary for computing the z-scores.

OPTIONAL ARGUMENTS:
newdata:
vector, matrix, data frame, or list to be charted. If missing, statistics, new.statistics, or both in object are charted.
type:
a character string or function specifying group statistics to compute. If a character string and one of "xbar", "s", "R", "p", "np", "u", or "c" built-in functions will be used. (See help(stats.xbar) for more information on these functions.) If the name of a function, it is used to compute the group summary statistics.
z.scores:
optional function to be used to compute the z-scores. Required if type is not one of "xbar", "s", "R", "p", "np", "u", or "c" or if there does not exist a function with name produced by paste("zs.", type, sep = "").
decision.int:
a numeric value in number of standard errors of the summary statistics at which the cumulative sum signals out of control. The default is 5.
se.shift:
the amount of shift to detect in the process measured in standard errors of the summary statistics. Twice what is referred to as the reference value which is the amount a summary statistic must exceed the target value in absolute value before it is added to the cumulative sum. The default is 1.
target:
a numeric value specifying the center of the process if other than the center component of object.
std.dev:
a numeric value specifying the overall within group standard deviation. If given, it is used to compute the standard error of the summary statistics instead of the std.dev component of object.
sizes:
a numeric vector specifying the sample sizes associated with each group of newdata. This may be used in conjunction with providing summary statistics rather than the original new data to newdata and is necessary if type is "p", "np" or "u". If of length 1, its value is assumed to be the size of all the groups.
labels:
character vector of labels to associate with each group. The default vector of labels is the "names" attribute for a vector or list, the first component of the "dimnames" attribute for a matrix, the "row.names" attribute of a data frame, or, if the appropriate attribute is NULL, the first n integers where n is the number of groups.
label.bounds:
a character vector of length two with labels for the decision interval boundaries. The first element is the label for the lower decision boundary and the second element is the label for the upper decision boundary. The default is c("LDB","UDB").
headstart:
a numeric value in standard errors of the group summary statistics at which to start the cumulative sums when reset = TRUE. The default is decision.interval/2.
reset:
a logical indicating whether the cumulative sums should be reset after an out-of-control signal. The default is FALSE.
add.stats:
a logical value indicating whether statistics should be listed at the bottom of the chart. The default is TRUE. Set add.stats = FALSE if you want to add your own text or lines to the chart.
chart.all:
a logical value indicating whether the cusums of the statistics component of object should be charted along with the cusums of the new.statistics component of object if present and the cusums of the summary statistics of newdata if given. The default of FALSE does not chart the statistics component of object.
ylim.min:
a numeric vector of values to be included in the computation of the approximate y-axis limits for the control chart. This can extend the range of the y-axis if necessary.
check.cl:
a logical indicating whether the summary statistics beyond the control limits of the Shewhart chart should be highlighted on the chart in addition to the decision boundary violations of the cumulative sums of the summary statistics. The default is FALSE. See DETAILS below.
highlight:
a list of plotting parameters to be used for highlighting the points outside the decision boundaries or beyond the Shewhart control limits. The default is highlight = list(pch = 1, col = 2). This can be a list of lists of plotting parameters (one list for each of the two kinds of violations---beyond the decision boundaries and beyond the Shewhart control limits) for highlighting, successively, each type of violation.

VALUE:
Invisibly returns a "cusum" object, which inherits from "shewhart" and "qcc", with all the components of object plus the following additional components if they dont already exist in object:

new.statistics:
a vector of group summary statistics for newdata with "names" attribute equal to labels. If new.statistics exists in object prior to calling cusum and newdata is given, the group summary statistics computed from newdata will be appended to the new.statistics component of object and the entire set of statistics returned.
new.sizes:
numeric vector of group sample sizes. If new.sizes exists in object prior to calling cusum and newdata is given, the group sample sizes computed from newdata will be appended to the new.sizes component of object and the entire set of sizes returned.
target:
the target argument if specified.
newdata.name:
a character string (vector of length 1) containing the name of the input data passed as newdata. If this exists in object prior to calling cusum and newdata is given, an "and" and the name of the input data will be appended to the newdata.name component of object and the entire character string returned.
cusum.upper:
a vector of the upper cumulative sums with "names" attribute equal to labels.
cusum.lower:
a vector of the lower cumulative sums with "names" attribute equal to labels.

Subsequent calls to cusum can pass the return value of a call to cusum, which includes newdata, in place of object with additional data in the newdata argument.


DETAILS:
The argument object provides the chart type or, more specifically, the type of group summary statistics (see help(qcc) for more details) and an estimate of the within group standard deviation if std.dev is not given. Based upon the summary statistics and the within group standard deviation, taken to be the process standard deviation, cumulative sums are computed and a chart produced for both upper and lower cumulative sums following a decision interval scheme discussed by Ryan (1989) and Wetherill and Brown (1991). The horizontal zero line on the chart divides the upper sums from the lower sums. The upper sums indicate a shift in the process above the target value and the lower sums indicate a shift in the process below the target value.

With the exception of cusum charts for s (the standard deviation), the vector of upper (U) and lower (L) cumulative sums are computed as U[i] <- max(0, ( z[i] - k ) + U[i-1] ) L[i] <- max(0, ( - z[i] - k ) + L[i-1] ) where k is the reference value equal to se.shift/2 and z <- ( statistics - target ) / std.err is the vector of z-scores computed by centering the group summary statistics about the target value equal to target object$target or object$center in that order of preference and dividing by the vector of standard errors of the group summary statistics.

For the cusum chart for s, only upper sums, U, are computed as follows:

U[i] <- max(0, statistics[i] - k * target + U[i-1]) where target is the target argument, object$target, or object$center in that order of preference.

The cusum chart is a composite plot of the upper sums, U, (the upper part of the plot) and the negative of the lower sums, -L (the lower part of the plot). The argument decision.int sets the width of the decision interval in standard errors of the summary statistics. The argument se.shift is used to specify the size of the shift you want to detect. Because Shewhart charts are primarily useful for detecting large shifts (2-3 standard errors) in the process' center, cusum charts are usually used in conjunction with Shewhart charts with settings appropriate for detecting 0.5 to 1.5 standard error shifts. se.shift specifies shifts in standard errors of the group summary statistics. By default se.shift = 1, for detecting a 1 standard error shift, and is equal to twice the reference value, k.

Usually when an out-of-control signal is generated by a large (or small) cumulative sum, a search is conducted and a cause is assigned and removed if possible to correct the process. In this case, the cumulative sums are reset and monitoring continues. By resetting the sums to something other than zero (called a headstart), a fast initial response (FIR) cusum is produced. This is useful for quickly detecting a process that hasn't been fully corrected. When reset = TRUE the cusums will be reset to headstart each time a cumulative sum exceeds one of the decision boundaries.

One additional improvement to cusum charts results from checking for a large deviation from the target value of a single group summary statistic. A group summary statistic greater than 3 standard errors from the target is equivalent to that summary statistic being outside 3-sigma Shewhart control limits. When check.cl = TRUE, summary statistics violating Shewhart control limits are flagged as well as large cumulative sums. If object is of class "shewhart", it will have a cntrl.limits component which will be used to check for violating summary statistics. Otherwise, 3-sigma Shewhart control limits, centered about target, will be computed to check for violating summary statistics.

The ylim.min argument can be used to expand the range of the y-axis if additional detail needs to be added to the chart. For example, additional limits can be added to a chart by setting ylim.min appropriately. If the additional limits are in addl.limits, then setting ylim.min = addl.limits will guarantee that the y-axis range is large enough for any subsequent calls to abline or lines. When low level plotting functions like abline are used to add detail to a cusum chart, you need to specify add.stats = FALSE in the call to cusum or else the coordinates will be incorrect for adding detail.


SIDE EFFECTS:
A cusum chart is plotted with decision interval boundaries computed based upon the within group standard deviation given by the std.dev argument, or the std.dev component of object in that order of preference. If newdata is given, the cusums of the summary statistics for newdata along with the cusums of any summary statistics contained in the new.statistics component of object are charted. If newdata is missing, the cusums of the new.statistics component of object is charted. If chart.all = TRUE the cusums of the statistics component of object is included on the chart. Repeated calls to cusum with the return value of the previous call as object and a newdata argument each time charts the summary statistics of the aggregate of the newdata arguments.

REFERENCES:
Montgomery, D. C. (1985). Statistical Quality Control. New York: John Wiley & Sons.

Ryan, T. P. (1989). Statistical Methods For Quality Improvement. New York: John Wiley & Sons.

Wetherill, G. B. and Brown, D. W. (1991). Statistical Process Control. New York: Chapman and Hall.


SEE ALSO:
qcc , shewhart , identify.cusum .

EXAMPLES:
cusum(qcc(matrix(rnorm(100), ncol = 5), type = "xbar"))