tcc {qicharts} | R Documentation |
Trellis Control Charts
Description
Run and control charts for multivariate data i trellis (grid) layout.
Usage
tcc(
n,
d,
x,
g1,
g2,
breaks,
notes,
data,
chart = c("run", "i", "mr", "xbar", "s", "t", "p", "c", "u", "g"),
multiply = 1,
freeze = NULL,
exclude,
target = NA,
n.sum = FALSE,
y.neg = TRUE,
y.percent = FALSE,
y.expand = NULL,
x.pad = 1,
x.date.format = NULL,
cl.lab = TRUE,
cl.decimals = NULL,
main,
xlab = "Subgroup",
ylab = "Value",
subtitle = NULL,
caption = NULL,
cex = 1,
pex = 1,
prime = TRUE,
flip = FALSE,
dots.only = FALSE,
print.summary = FALSE,
...
)
Arguments
n |
Numerator, numeric vector of counts or measures to plot. Mandatory. |
d |
Denominator, numeric vector of subgroup sizes. Mandatory for P and U charts. |
x |
Subgrouping vector used for aggregating data by subgroup and making x-labels. Mandatory for Xbar and S charts. |
g1 |
Grouping vector 1 used for trellis layout (facets). |
g2 |
Grouping vector 2 used for trellis layout (facets). |
breaks |
Numeric vector of break points. Useful for splitting graph in two or more sections with separate center line and control limits. |
notes |
Character vector of notes to be added to individual. data points. |
data |
Data frame containing variables. |
chart |
Type of control chart. Possible types are:
|
multiply |
Integer indicating a number to multiply y axis by, e.g. 100
for percents rather than proportions. See also |
freeze |
Number identifying the last data point to include in
calculations of center and limits (ignored if |
exclude |
Numeric vector of data points to exclude from runs analysis and calculations of center and control lines (same for each facet). |
target |
Numeric value indicating a target value to be plotted as a horizontal line (same for each facet). |
n.sum |
Logical value indicating whether the mean (default) or sum of numerator (n argument) per subgroup should be plotted. Only relevant for run, C, and I charts with multiple counts per subgroup. |
y.neg |
Logical value. If TRUE (default), the y axis is allowed to be negative (only relevant for I and Xbar charts). |
y.percent |
Logical. If TRUE, formats y axis labels as percent. |
y.expand |
Numeric value to include in y axis. Useful e.g. for beginning y axis at zero. |
x.pad |
Number indicating expansion of x axis to make room for center line labels. |
x.date.format |
Date format of x axis labels. See |
cl.lab |
Logical value. If TRUE (default), plots center line labels. |
cl.decimals |
Number of decimals on center line labels. |
main |
Character string specifying the title of the plot. |
xlab |
Character string specifying the x axis label. |
ylab |
Character string specifying the y axis label. |
subtitle |
Character string specifying the subtitle. |
caption |
Character string specifying the caption. |
cex |
Number indicating the amount by which text should be magnified. |
pex |
Number indicating the amount by which plotting symbols should be magnified. |
prime |
Logical value, If TRUE (default unless |
flip |
Logical. If TRUE rotates the plot 90 degrees. |
dots.only |
Logical value. If TRUE, data points are not connected by lines, prime is forced to be FALSE, and runs analysis is not performed. Useful for comparison and funnel plots. |
print.summary |
Logical. If TRUE, prints summary of tcc object. |
... |
Further arguments to ggplot function. |
Details
tcc()
is a wrapper function for ggplot2()
that makes
multivariate run and control charts. It takes up to two grouping variables
for multidimensional trellis plots.
Note that, in contrast to the qic() function, the prime argument defaults to TRUE, which means that control limits of P and U charts by default incorporate between-subgroup variation as proposed by Laney (2002).
Value
An object of class ggplot.
References
Runs analysis:
Jacob Anhoej, Anne Vingaard Olesen (2014). Run Charts Revisited: A Simulation Study of Run Chart Rules for Detection of Non-Random Variation in Health Care Processes. PLoS ONE 9(11): e113825. doi: 10.1371/journal.pone.0113825 .
Jacob Anhoej (2015). Diagnostic Value of Run Chart Analysis: Using Likelihood Ratios to Compare Run Chart Rules on Simulated Data Series. PLoS ONE 10(3): e0121349. doi: 10.1371/journal.pone.0121349
Mark F. Schilling (2012). The Surprising Predictability of Long Runs. Math. Mag. 85, 141-149.
Zhenmin Chen (2010). A note on the runs test. Model Assisted Statistics and Applications 5, 73-77.
Calculation of control limits:
Douglas C. Montgomery (2009). Introduction to Statistical Process Control, Sixth Edition, John Wiley & Sons.
James C. Benneyan (2001). Number-Between g-Type Statistical Quality Control Charts for Monitoring Adverse Events. Health Care Management Science 4, 305-318.
Lloyd P. Provost, Sandra K. Murray (2011). The Health Care Data Guide: Learning from Data for Improvement. San Francisco: John Wiley & Sons Inc.
David B. Laney (2002). Improved control charts for attributes. Quality Engineering, 14(4), 531-537.
Examples
# Run chart of 24 random normal variables
tcc(rnorm(24))
# Build data frame for examples
d <- data.frame(x = rep(1:24, 4),
mo = (rep(seq(as.Date('2014-1-1'),
length.out = 24,
by = 'month'),
4)),
n = rbinom(4 * 24, 100, 0.5),
d = round(runif(4 * 24, 90, 110)),
g1 = rep(c('a', 'b'), each = 48),
g2 = rep(c('A', 'B'), each = 24))
# Run chart with two grouping variables
tcc(n, d, mo, g1 = g1, g2 = g2, data = d)
# P chart
tcc(n, d, mo, g1 = g1, g2 = g2, data = d, chart = 'p')
# P chart with baseline fixed to the first 12 data points
tcc(n, d, mo, g1 = g1, g2 = g2, data = d, chart = 'p', freeze = 12)
# P chart with two breaks and summary output
tcc(n, d, mo, g1 = g1, g2 = g2, data = d, chart = 'p',
breaks = c(12, 18), print.summary = TRUE)