Plot a Shewhart Quality Control Chart

DESCRIPTION:
Plots a Shewhart quality control chart based on a "qcc" object and optional within group standard deviation or control limit specifications. Rules may be applied to the chart and violating points highlighted.

SIMPLE:
shewhart(object, newdata)

USAGE:
shewhart(object, newdata, type, limits, target, std.dev, sizes,
         labels, label.limits = c("LCL","UCL"),
         confidence.level = 0.999, nsigmas, add.stats = T,
         chart.all = F, ylim.min = NULL, rules = shewhart.rules,
         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 plot and the within group standard deviation necessary for computing the control limits.

OPTIONAL ARGUMENTS:
newdata:
vector, matrix, data frame, or list to be charted. If missing, statistics, new.statistics, or both in object are charted depending on the argument chart.all.
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.
limits:
a numeric vector or matrix or a function specifying the control limits. If a vector, the first element equals the lower control limit and the second element equals the upper control limit. If a matrix, the first column equals the heights of the step function defining the lower control limits and the second column equals the heights of the step function defining the upper control limits. If a function, it is used to compute the control limits using the std.dev component in object or the std.dev argument if it is given. If missing, the limits function determined by type is used to compute the control limits. See DETAILS below.
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 control limits instead of the std.dev component of object.
sizes:
vector of the number of observations in each group of newdata for xbar, s, and R charts. For p, np, and u charts, sizes corresponds to the number of units examined. For c charts, sizes is assumed to be 1. sizes 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 for each group of newdata. The default vector of labels is the "names" attribute if newdata is a vector or list, the first component of the "dimnames" attribute if newdata is a matrix, the "row.names" attribute if newdata is a data frame, or, if the appropriate attribute is NULL, the first n integers where n is the number of groups.
label.limits:
a character vector of length two with labels for the control limits. The first element is the label for the lower control limit and the second element is the label for the upper control limit. The default is c("LCL","UCL").
confidence.level:
a numeric value between 0 and 1 specifying the confidence level of the computed probability limits. The default is 0.999 which corresponds to 3.29*sigma limits for normally distributed group summary statistics.
nsigmas:
a numeric value specifying one-half the width of the control limits in number of standard errors of the group summary statistics. If missing, confidence.level is used.
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 statistics component of object should be plotted along with the new.statistics component of object if present and the summary statistics of newdata if given. The default of FALSE does not plot 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.
rules:
a function of rules to apply to the chart. The default is shewhart.rules. See DETAILS below.
highlight:
a list of plotting parameters to be used for highlighting the points violating rules. The default is highlight = list(pch = 1, col = 2). If more than one rule is applied to the chart, this can be a list of lists of plotting parameters for highlighting successively the points violating each rule.
...:
additional arguments to rules.

VALUE:
invisibly returns a "shewhart" object, which inherits from "qcc", with all the components of object plus the following additional arguments:
new.statistics:
a vector of group summary statistics for newdata with "names" attribute equal to labels. If this exists in object prior to calling shewhart 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:
vector of group sample sizes If a new.sizes component of object exists prior to calling shewhart and newdata is given, new.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.
cntrl.limits:
the control limits
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 shewhart 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.

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


DETAILS:
The argument object provides the chart type (see help(qcc) for more details) and an estimate for the within group standard deviation if std.dev is not given as an argument. The control limits are computed and a Shewhart chart is produced for three different sets of summary statistics depending on the value of chart.all and whether newdata is given. 1) If chart.all = F and newdata is given, any summary statistics in the new.statistics component of object and the summary statistics for newdata computed depending upon type will be charted. 2) If chart.all = F and newdata is missing, only the statistics in the new.statistics component of object will be charted. 3) If chart.all = T, the statistics component and the new.statistics component of object will be charted along with the summary statistics of newdata if given.

If limits is missing, shewhart will use the cntrl.limits component of object, if it exists, as the control limits for the chart. If limits is missing and there is not a cntrl.limits component of object, appropriate default functions compute the control limits for the chart. The name of the default function that computes the control limits is formed by pasting together "limits", a period, and the value of type. Thus the control limits of an xbar chart are computed by limits.xbar. By default, probability limits are computed with equal tail probabilities computed as (1 - confidence.level)/2. The control limits are centered in probability about target if it is given, the target component of object if present, or the center component of object, in that order or preference. If nsigmas is given, the control limits are computed as target (or center if target and object$target are missing) plus or minus nsigmas times the standard errors of the group summary statistics. If length(unique(sizes)) > 1, the summary statistics' standard errors will be different, and the control limits are computed as step functions. For more details on how the control limits are computed for Shewhart charts see the help file for the appropriate function (e.g. limits.xbar for the xbar chart).

If limits is given as a vector or matrix, the values specify the control limits. If limits is a function, then it must return a vector or matrix specifying the control limits. If it returns a vector, the first element is the lower control limit and the second element is the upper control limit. If it returns a matrix, the first column corresponds to the lower control limits and the second column corresponds to the upper control limits.

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 are used to add detail to a Shewhart chart, you need to specify add.stats = FALSE in the call to shewhart or else the coordinates will be incorrect for adding detail.

The rules argument specifies a function to determine points which violate a given (set of) rule(s). For example, the beyond.limits function returns the indices of the charted statistics which are beyond the control limits. The indicated points are highlighted according the plotting parameters specified by highlight. Other rules functions which are provided are runs.target for determining all points in a run, for a given run length, above or below the target value and shewhart.rules which combines beyond.limits and runs.target. Although rules can be used in this way to more quickly detect small shifts (on the order of 0.5 - 1.5 standard errors) in the process, cusum charts are preferable. See help(cusum) for more details.


SIDE EFFECTS:
A Shewhart chart is plotted with control limits 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 summary statistics for newdata along with any summary statistics contained in the new.statistics component of object are charted. If newdata is missing, the new.statistics component of object is charted. If chart.all = TRUE the statistics component of object is included on the chart. Repeated calls to shewhart 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.

SEE ALSO:
qcc , shewhart.rules , beyond.limits , runs.target , cusum .

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