Title: | Quality Improvement Charts |
---|---|
Description: | Functions for making run charts, Shewhart control charts and Pareto charts for continuous quality improvement. Included control charts are: I, MR, Xbar, S, T, C, U, U', P, P', and G charts. Non-random variation in the form of minor to moderate persistent shifts in data over time is identified by the Anhoej rules for unusually long runs and unusually few crossing [Anhoej, Olesen (2014) <doi:10.1371/journal.pone.0113825>]. Non-random variation in the form of larger, possibly transient, shifts is identified by Shewhart's 3-sigma rule [Mohammed, Worthington, Woodall (2008) <doi:10.1136/qshc.2004.012047>]. |
Authors: | Jacob Anhoej [aut, cre] |
Maintainer: | Jacob Anhoej <[email protected]> |
License: | GPL-3 |
Version: | 0.7.5 |
Built: | 2024-11-11 04:45:15 UTC |
Source: | https://github.com/anhoej/qicharts2 |
The Bernoulli CUSUM chart is useful for monitoring rare events data, e.g. surgical site infections and other types of complications. Based on Neuburger et al. (2017) doi:10.1136/bmjqs-2016-005526.
bchart( x, target, or = 2, limit = 3.5, title = "", ylab = "CUSUM", xlab = "Case #" )
bchart( x, target, or = 2, limit = 3.5, title = "", ylab = "CUSUM", xlab = "Case #" )
x |
Logical, vector of successes and failures. |
target |
Baseline risk (0-1) or number (>1) of last observation to end baseline period. |
or |
Positive odds ratio of minimal detectable change relative to baseline risk. |
limit |
Control limit. |
title |
Chart title. |
ylab |
Y axis label. |
xlab |
X axis label. |
Note that the diagnostic properties of the Bernoulli CUSUM chart is highly dependent on the choice of parameters, target, or and limit, and that these parameters should be decided by people with a solid understanding of the process at hand. The default parameters, or = 2 and limit = 3.5, should, however, work for most processes where the baseline (target) level is about 1 halving of the event rate relative to the target.
An object of class ggplot.
# Generate 1000 random successes and failures with success rate = 0.02 set.seed(1) y <- rbinom(1000, 1, 0.02) # Plot bchart assuming success rate = 0.01, OR = 2, control limits = +/- 3.5. bchart(y, target = 0.01) # Plot bchart of CABG mortality using the first 200 surgeries to estimate target. bchart(cabg$death, target = 200) # Plot bchart of CABG readmissions setting the control limits = +/-5. bchart(cabg$readmission, target = 200, limit = 5)
# Generate 1000 random successes and failures with success rate = 0.02 set.seed(1) y <- rbinom(1000, 1, 0.02) # Plot bchart assuming success rate = 0.01, OR = 2, control limits = +/- 3.5. bchart(y, target = 0.01) # Plot bchart of CABG mortality using the first 200 surgeries to estimate target. bchart(cabg$death, target = 200) # Plot bchart of CABG readmissions setting the control limits = +/-5. bchart(cabg$readmission, target = 200, limit = 5)
A dataset with data on individual coronary artery bypass graft operations.
cabg
cabg
A data frame with 2205 rows and 6 variables:
data Date of operation.
age Patient age in years.
gender Patient gender.
los Length og stay in days.
death TRUE if patient died within 30 days after surgery.
readmission TRUE if patient were readmitted for any reason within 30 days after surgery.
Omitted for privacy concerns.
A dataset with data on hospital acquired Clostridium difficile infections (CDI) before and after an intervention to reduce the risk of CDI.
cdi
cdi
A data frame with 36 rows and 5 variables:
month Month of observation.
n Number of hospital acquired CDI.
days Number of risk days. A risk day is a patient day without CDI.
period Factor indicating the period 'pre' or 'post' intervention.
notes Annotations.
www.esundhed.dk (Amager Hvidovre Hospital).
A dataset with data on adverse events during hospitalisation found by the Global Trigger Tool.
gtt
gtt
A data frame with 340 rows and 11 variables:
admission_id Admission ID.
admission_dte Date of admission.
discharge_dte Date of discharge.
month Month of discharge.
days Duration of hospital stay in days.
harms Number of adverse events.
E-I Type of adverse event by severity category. E-F: Temporary harm; G-H: Permanent harm; I: Fatal harm.
Omitted for privacy concerns.
https://www.ihi.org/resources/white-papers/ihi-global-trigger-tool-measuring-adverse-events
A dataset containing the number of hospital acquired bacteremia, Clostridium difficile infections, and urinary tract infections in six hospitals in the Capital Region of Denmark 2015-2016.
hospital_infections
hospital_infections
A data frame with 432 rows and 5 variables:
hospital Abbreviated hospital name.
infection Type of infection. BAC: Bacteremia, CDI: Clostridium difficile infection. UTI: Urinary tract infection.
month First day of month.
n Number of cases.
days Number of risk days. A risk day is a patient day without infection.
www.esundhed.dk (Capital Region of Denmark).
The number of attendances to major accident and emergency hospital departments in the NHS that were seen within 4 hours of arrival over twenty weeks.
nhs_accidents
nhs_accidents
A data frame with 20 rows and 3 variables:
i Week number.
r Attendances seen within 4 hours.
n Total number of attendances.
Mohammed MA, et al. Quality and Safety in Health Care 2013;22:362–368. doi:10.1136/bmjqs-2012-001373.
Creates a pareto chart from a categorical variable
paretochart( x, title = "", subtitle = NULL, caption = NULL, ylab = NULL, xlab = NULL, x.angle = NULL, useNA = FALSE, print.data = FALSE )
paretochart( x, title = "", subtitle = NULL, caption = NULL, ylab = NULL, xlab = NULL, x.angle = NULL, useNA = FALSE, print.data = FALSE )
x |
Categorical variable to plot. |
title |
Chart title. |
subtitle |
Chart subtitle. |
caption |
Chart caption. |
ylab |
Y axis label. |
xlab |
X axis label. |
x.angle |
Number indicating the angle of x axis labels. |
useNA |
If TRUE, NA values will be included in the analysis. |
print.data |
If TRUE, prints data frame with results. |
An object of class ggplot.
# Generate categorical vector x <- rep(LETTERS[1:9], c(256, 128, 64, 32, 16, 8, 4, 2, 1)) # Make paretochart paretochart(x) # Save paretochart object to variable p <- paretochart(x) # Print data frame p$data
# Generate categorical vector x <- rep(LETTERS[1:9], c(256, 128, 64, 32, 16, 8, 4, 2, 1)) # Make paretochart paretochart(x) # Save paretochart object to variable p <- paretochart(x) # Print data frame p$data
The qic()
function creates run charts and Shewhart control charts for
process control and improvement. Included control charts are: I, MR, Xbar, S,
T, C, U, U', P, P', and G charts.
qic( x, y = NULL, n = NULL, data = NULL, facets = NULL, notes = NULL, chart = c("run", "i", "mr", "xbar", "s", "t", "p", "pp", "c", "u", "up", "g"), agg.fun = c("mean", "median", "sum", "sd"), method = c("anhoej", "bestbox", "cutbox"), multiply = 1, freeze = NULL, part = NULL, exclude = NULL, target = NA * 1, cl = NA * 1, nrow = NULL, ncol = NULL, scales = "fixed", title = "", ylab = "Value", xlab = "Subgroup", subtitle = NULL, caption = NULL, part.labels = NULL, show.labels = is.null(facets), show.95 = FALSE, decimals = 1, point.size = 1.5, x.period = NULL, x.format = NULL, x.angle = NULL, x.pad = 1, y.expand = NULL, y.neg = TRUE, y.percent = FALSE, y.percent.accuracy = NULL, show.grid = FALSE, flip = FALSE, strip.horizontal = FALSE, print.summary = FALSE, return.data = FALSE )
qic( x, y = NULL, n = NULL, data = NULL, facets = NULL, notes = NULL, chart = c("run", "i", "mr", "xbar", "s", "t", "p", "pp", "c", "u", "up", "g"), agg.fun = c("mean", "median", "sum", "sd"), method = c("anhoej", "bestbox", "cutbox"), multiply = 1, freeze = NULL, part = NULL, exclude = NULL, target = NA * 1, cl = NA * 1, nrow = NULL, ncol = NULL, scales = "fixed", title = "", ylab = "Value", xlab = "Subgroup", subtitle = NULL, caption = NULL, part.labels = NULL, show.labels = is.null(facets), show.95 = FALSE, decimals = 1, point.size = 1.5, x.period = NULL, x.format = NULL, x.angle = NULL, x.pad = 1, y.expand = NULL, y.neg = TRUE, y.percent = FALSE, y.percent.accuracy = NULL, show.grid = FALSE, flip = FALSE, strip.horizontal = FALSE, print.summary = FALSE, return.data = FALSE )
x |
Vector of subgroup values to plot along the x axis. |
y |
Vector of measures or counts to plot on the y axis (numerator). |
n |
Vector of subgroup sizes (denominator). |
data |
Data frame containing variables used in the plot. |
facets |
One or two sided formula with factors used for facetting plots. |
notes |
Character vector of notes to be added to individual data points. |
chart |
Character value indicating the chart type. Possible values are: 'run' (default), 'i', 'mr', 'xbar', 't', 's', 'c', 'u', 'up', 'p', 'pp', and 'g'. |
agg.fun |
Aggregate function for summarising the y variable if there are more than one observation per subgroup. Only relevant for run charts and I charts. Possible values are: 'mean' (default), 'median', 'sum', and 'sd'. |
method |
Character indicating the method used for runs analysis. One of 'anhoej' (default), 'bestbox', and 'cutbox'. EXPERIMENTAL! |
multiply |
Number indicating a number to multiply y axis by, e.g. 100
for percents rather than proportions. See also |
freeze |
Integer indicating the last data point to include in calculation of baseline parameters for centre and control lines. Ignored if part argument is given. |
part |
Either integer vector indicating data points before recalculation of centre and control lines or character vector indicating chart parts. |
exclude |
Integer vector indicating data points to exclude from calculations of centre and control lines. |
target |
Numeric, either a single value indicating a target value to be plotted as a horizontal line or a vector for variable target line. |
cl |
Numeric, either a single value indicating the centre line if known in advance or a vector for variable centre line. |
nrow , ncol
|
Number indicating the preferred number of rows and columns in facets. |
scales |
Character string, one of 'fixed' (default), 'free_y', 'free_x', or 'free' indicating whether y and x axis scales should be the same for all panels or free. |
title |
Character string specifying the title of the plot. |
ylab |
Character string specifying the y axis label. |
xlab |
Character string specifying the x axis label. |
subtitle |
Character string specifying the subtitle. |
caption |
Character string specifying the caption. |
part.labels |
Character vector specifying labels for chart parts created with the freeze or part argument. |
show.labels |
Logical indicating whether to show labels for centre and control lines on chart. Defaults to TRUE when facets argument is NULL. |
show.95 |
Logical indicating whether to show 95 control limits on chart. Defaults to FALSE. |
decimals |
Integer indicating the preferred number of decimals in centre and control line labels. |
point.size |
Number specifying the size of data points. |
x.period |
Character string specifying the interval cut points of
datetime x values used for aggregating y values by week, month, etc. See
the breaks argument of |
x.format |
Date format of x axis labels. See |
x.angle |
Number indicating the angle of x axis labels. |
x.pad |
Number indicating expansion of x axis to make room for axis labels. |
y.expand |
Numeric value to include in y axis. Useful e.g. for starting the y axis at zero. |
y.neg |
If TRUE (default), the y axis is allowed to be negative (only relevant for I and Xbar charts). |
y.percent |
If TRUE, formats y axis labels as percentages. |
y.percent.accuracy |
A number to round percentage labels on y axis. Use 1 to show no decimals, 0.1 to show 1 decimal etc. |
show.grid |
If TRUE, shows grid. |
flip |
If TRUE, rotates the plot 90 degrees. |
strip.horizontal |
If TRUE, makes y strip horizontal. |
print.summary |
If TRUE, prints summary. |
return.data |
If TRUE, returns underlying data frame. |
Non-random variation in the form of minor to moderate persistent shifts in data over time is (by default) identified by the Anhoej rules for unusually long runs and unusually few crossing. Use the EXPERIMENTAL method argument to apply the bestbox or cutbox methods as described in Anhøj & Wentzel-Larsen (2020) doi:10.1371/journal.pone.0233920.
Special cause variation in the form of larger, possibly transient, shifts in data is identified by Shewhart's 3-sigma rule (Mohammed, Worthington, Woodall (2008) doi:10.1136/qshc.2004.012047).
A qic
object. Inherits from 'ggplot'.
vignette('qic')
.
# Lock random number generator to make reproducible results. set.seed(2) # Generate vector of 24 random normal numbers y <- rnorm(24) # Run chart qic(y) # I control chart qic(y, chart = 'i') # U control chart from build-in data set of hospital infection rates faceted # by hospital and type of infection. qic(month, n, n = days, data = hospital_infections, facets = infection ~ hospital, chart = 'u', multiply = 10000, title = 'Hospital infection rates', ylab = 'Number of infections per 10.000 risk days', xlab = 'Month')
# Lock random number generator to make reproducible results. set.seed(2) # Generate vector of 24 random normal numbers y <- rnorm(24) # Run chart qic(y) # I control chart qic(y, chart = 'i') # U control chart from build-in data set of hospital infection rates faceted # by hospital and type of infection. qic(month, n, n = days, data = hospital_infections, facets = infection ~ hospital, chart = 'u', multiply = 10000, title = 'Hospital infection rates', ylab = 'Number of infections per 10.000 risk days', xlab = 'Month')
qicharts2
packageStatistical Process Control chart for R
#' See the README on https://github.com/anhoej/qicharts2/
Prints summary of a qic object
## S3 method for class 'qic' summary(object, ...)
## S3 method for class 'qic' summary(object, ...)
object |
A qic object. |
... |
For compatibility with generic summary function. |
A data frame of summary values of each facet and part of a qic plot.
facet1 Vertical facets.
facet2 Horizontal facets
part Number of chart part when argument break.points is given.
aLCL Average of lower control limit.
CL Centre line.
aUCL Average of upper control limit.
longest.run Length of the longest run of data points on the same side of the centre line.
longest.run.max Upper limit of expected length of longest run.
n.crossings Number of times the data line crosses the centre line.
n.crossings.min Lower limit of expected number of crossings.
runs.signal 1 if either longest run or number of crossings are outside expected limits.
sigma.signal Number of data points outside control limits.
p <- qic(rnorm(24), chart = 'i') p summary(p)
p <- qic(rnorm(24), chart = 'i') p summary(p)