View source: R/control_chart.R
| control_chart | R Documentation |
Builds a control chart of a quantity that should stay constant over time, such as the intensity of an internal standard line, a line ratio of a check sample or a plasma temperature, to detect drifts and shifts of the instrument: a Shewhart chart of individual values, an exponentially weighted moving average (EWMA) or a cumulative sum (CUSUM).
control_chart(
x,
order = NULL,
method = "shewhart",
baseline = NULL,
center = NULL,
sigma = NULL,
width = 3,
rules = TRUE,
lambda = 0.2,
allowance = 0.5,
decision = 5
)
x |
A numeric vector of the monitored quantity. |
order |
The time or acquisition order of the values (numbers, dates or date-times), by which they are sorted. By default, their position. |
method |
|
baseline |
The measurements that set the center and the standard deviation: the number of first values, or a logical or index vector. By default, all values. |
center, sigma |
The center and standard deviation of the process, if known. |
width |
The width of the limits, in standard deviations, for the Shewhart and EWMA charts. Default is 3. |
rules |
A logical: apply the Western Electric rules to the Shewhart
chart ( |
lambda |
The smoothing constant of the EWMA chart. Default is 0.2. |
allowance, decision |
The allowance |
The center line and the standard deviation \sigma are estimated
from the baseline measurements (by default, all of them), unless given:
the mean, and the mean moving range of consecutive values divided by
1.128, which, unlike the standard deviation, is little inflated by a
drift.
"shewhart": the values themselves, with limits at width
\sigma from the center. With rules = TRUE, the Western
Electric rules also flag (1) a value beyond the limits, (2) two of
three consecutive values beyond 2\sigma on the same side, (3)
four of five beyond 1\sigma on the same side and (4) eight
consecutive values on the same side of the center. It detects large
shifts quickly.
"ewma": z_t = \lambda x_t + (1 - \lambda) z_{t-1}, starting at
the center, with limits at width
\sigma \sqrt{\lambda / (2 - \lambda) (1 - (1 - \lambda)^{2t})}.
Small values of \lambda detect small, slow drifts.
"cusum": the tabular CUSUM, the sums of the deviations beyond
allowance \sigma above and below the center,
C^+_t = \max(0, x_t - \mu - k\sigma + C^+_{t-1}) and likewise
below, with a signal when a sum exceeds decision \sigma. It
detects small persistent shifts.
A tibble of class specproc_control_chart, one row per value in
time order: order, value, the plotted statistic (the value, the
EWMA, or for the CUSUM the upper sum, with the lower sum in
lower_sum), the center, the lower and upper limits, whether the
point is a signal, and, for the Shewhart chart, the first Western
Electric rule broken. The method, center, standard deviation and
baseline are in the attributes. Draw it with plot_control_chart().
Christian L. Goueguel
Montgomery, D.C. (2019). Introduction to Statistical Quality Control, 8th ed. Wiley, Hoboken.
Western Electric Company (1956). Statistical Quality Control Handbook. Western Electric, Indianapolis.
plot_control_chart(), line_intensities()
# a check-sample ratio that drifts after the 60th measurement
set.seed(1)
ratio <- 1 + c(rep(0, 60), seq(0, 0.06, length.out = 40)) + rnorm(100, sd = 0.02)
shewhart <- control_chart(ratio, baseline = 40)
shewhart[shewhart$signal, ]
plot_control_chart(shewhart)
# the EWMA detects the slow drift earlier
plot_control_chart(control_chart(ratio, method = "ewma", baseline = 40))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.