qic: Quality improvement charts

Description Usage Arguments Details Value References Examples

View source: R/qic.R

Description

Run and control charts for quality improvement and control

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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",
  llabs = c("LCL", "CL", "UCL", "TRG"),
  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 events chart.

  • "p": proportions chart.

  • "c": counts chart.

  • "u": rates chart.

  • "g": cases between events chart.

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 argument (if provided) will be ignored.

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

llabs

Character vector with four elements specifying labels for lower control limit, centre line, upper control limit and target line respectively

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.

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.

Value

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

References

Runs analysis:

Calculation of control limits:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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)

Example output

qicharts will no longer be maintained. Please consider moving to qicharts2: https://anhoej.github.io/qicharts2/.

qicharts documentation built on April 20, 2021, 5:09 p.m.