Learn R Programming

qicharts (version 0.4.1)

qic: Quality improvement charts

Description

Run and control charts for quality improvement and control

Usage

qic(y, n, x, data, chart = c("run", "i", "mr", "xbar", "s", "t", "p", "c",
  "u", "g"), notes = NULL, cl = NULL, agg.fun = c("mean", "sum"),
  ylim = NULL, target = NULL, direction = NULL, freeze = NULL,
  breaks = NULL, exclude = NULL, negy = TRUE, dots.only = FALSE,
  multiply = 1, prime = FALSE, standardised = FALSE,
  x.format = "%Y-%m-%d", nint = 5, cex = 0.8, main,
  xlab = "Subgroup", ylab = "Indicator", sub = NULL, decimals = NULL,
  pre.text = "Before data", post.text = "After data",
  rag.text = c("Improve", "Investigate", "Control"), runvals = FALSE,
  linevals = TRUE, plot.chart = TRUE, print.out = FALSE, ...)

Arguments

y
Numeric vector of counts or measures to plot. Mandatory.
n
Numeric vector of sample sizes. Mandatory for P and U charts.
x
Subgrouping vector used for aggregating data and making x-labels. Mandatory for Xbar and S charts.
data
Data frame containing variables.
chart
Type of control chart. Possible types are:
  • "run": run chart (default).
  • "i": individuals chart.
  • "mr": moving range chart.
  • "xbar": sample average chart.
  • "s": sample standard deviation chart.
  • "t": time between
notes
Character vector of notes to be added to individual. data points.
cl
Value specifying the center line (if known). Must be of length one or same as number of subgroups (for variable center line).
agg.fun
String specifying the aggregate function if there is more than one value per subgroup. Possible values are 'mean' and 'sum'. Only relevant if you want to aggregate count data with run charts or I charts. If agg.fun = 'sum', the n
ylim
Range of y axis limits.
target
Value specifying a target line to plot.
direction
Value indication direction of improvement, 0 (down) or 1 (up).
freeze
Number identifying the last data point to include in calculations of center and limits (ignored if breaks argument is given).
breaks
Numeric vector of break points. Useful for splitting graph in two or more sections with separate center line and control limits.
exclude
Numeric vector of data points to exclude from calculations of center and control lines.
negy
Logical value, if TRUE, the y axis is allowed to be negative (only relevant for I and Xbar charts).
dots.only
Logical value. If TRUE, data points are not connected by lines and runs analysis is not performed. Useful for comparison and funnel plots.
multiply
Integer indicating a number to multiply y axis by, e.g. 100 for percents rather than proportions.
prime
Logical value, if TRUE, control limits incorporate between-subgroup variation as proposed by Laney (2002). This is recommended for data involving very large sample sizes. Only relevant for P and U charts.
standardised
Logical value, if TRUE, creates a standardised control chart, where points are plotted in standard deviation units along with a center line at zero and control limits at 3 and -3. Only relevant for P, U and Xbar charts.
x.format
Date format of x axis labels. See ?strftime for date formats.
nint
Number indicating (approximately) the desired number of tick marks on the x axis.
cex
Number indicating the amount by which text and symbols should be magnified.
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.
sub
Character string specifying a subtitle to be printed in the lower left corner of the plot.
decimals
Integer indicating the number of decimals shown for center and limits on the plot. Default behaviour is smart rounding to at least two significant digits.
pre.text
Character string labelling pre-freeze period
post.text
Character string labelling post-freeze period
rag.text
Character vector with three elements indicating "traffic light" labels.
runvals
Logical value, if TRUE, prints statistics from runs analysis on plot.
linevals
Logical value, if TRUE, prints values for center and control lines on plot.
plot.chart
Logical value, if TRUE, prints plot.
print.out
Logical value, if TRUE, prints return value
...
Further arguments to plot function.

Value

  • A list of of class qic containing values and parameters of the qic plot.

Details

If chart is not specified, qic() plots a run chart. Non-random variation will be marked by a dashed, yellow center line (the median) if either the longest run of data points above or below the median is longer than predicted or if the graph crosses the median fewer times than predicted (see references for details).

Only the y argument giving the count or measure of interest is mandatory for a run chart. If a denominator argument, n, is given, $y/n$ will be plotted. If a subgrouping argument, x, is given, $sum(y)/sum(n)$, within each subgroup will be plotted. This behaviour can be modified using the agg.fun argument.

With controlcharts, data aggregation by subgroups is handled according to chart type. For P, U, and I charts, data are aggregated as described for the run chart. For the C chart, the sum of counts, sum(y), within each subgroups will be plotted.

For Xbar and S charts, the subgrouping argument, x, is mandatory. However, the sample size argument, n, is irrelevant and will be ignored.

The subgrouping argument, x, is irrelevant for T and G charts, and, if given, an error will occur if any subgroup has more than one element.

If more than one note is present within any subgroup, the first note (alphabetically) is chosen.

If both prime and standardised are TRUE, points are plotted in units corresponding to Laney's modified "standard deviation", which incorporates the variation between subgroups.

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 this code
set.seed(1)
# Run chart of 24 samples of a random continuous variable
# with an approximate mean = 12 and standard deviation = 3.
y <- rnorm(24, 12, 3)
qic(y)

# Add subgroup vector (dates) and a target
x <- seq.Date(as.Date('2013-08-04'), by = 'week', length = 24)
qic(y, x = x, target = 16)

# Individuals control chart
qic(y, x = x, chart = 'i')

# Xbar control chart, sample size = 5
y <- rnorm(5 * 24)
x <- rep(x, 5)
qic(y, x = x, chart = 'xbar')

# Create data frame with counts and sample sizes by week
d <- data.frame(week = seq.Date(as.Date('2013-08-04'),
                                by = 'week',
                                length = 36),
                y = c(rbinom(24, 20, 0.5), rbinom(12, 20, 0.8)),
                n = round(rnorm(36, 20, 2)))

# Proportions control chart
qic(y, n, x = week, data = d[1:24,], chart = 'p')

# Introduce change in process performance
qic(y, n, x = week, data = d, chart = 'p')

# Freeze baseline to first 24 samples
qic(y, n, x = week, data = d, chart = 'p', freeze = 24)

# Break control chart before and after change
qic(y, n, x = week, data = d, chart = 'p', breaks = 24)

# Introduce extreme sample value and notes
d$a <- ''
d$a[30] <- 'Extreme value'
d$y[30] <- 1
qic(y, n, x = week, data = d, chart = 'p',
    breaks = 24,
    notes = a)

# Exclude value from calculations
d$a[30] <- 'Value excluded from calculations'
qic(y, n, x = week, data = d, chart = 'p',
    breaks = 24,
    notes = a,
    exclude = 30)

Run the code above in your browser using DataLab