tcc: Trellis Control Charts

Description Usage Arguments Details Value References Examples

View source: R/tcc.R

Description

Run and control charts for multivariate data i trellis (grid) layout.

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
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:

  • "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.

multiply

Integer indicating a number to multiply y axis by, e.g. 100 for percents rather than proportions. See also y.percent argument.

freeze

Number identifying the last data point to include in calculations of center and limits (ignored if breaks argument is given).

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 ?strftime() for possible date formats.

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 dots.only = TRUE), control limits incorporate between-subgroup variation as proposed by Laney (2002). Only relevant for P and U charts.

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:

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
# 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)

Example output

qicharts will no longer be maintained. Please consider moving to qicharts2: https://anhoej.github.io/qicharts2/.
   g1 g2 breaks n.obs n.useful        cl       lcl       ucl limits.signal
1   a  A      1    12       12 0.5041667 0.3103965 0.6979368         FALSE
2   a  A      2     6        6 0.5035336 0.3506604 0.6564068         FALSE
3   a  A      3     6        6 0.4907563 0.2063913 0.7751213         FALSE
4   a  B      1    12       12 0.4706362 0.2496553 0.6916172         FALSE
5   a  B      2     6        6 0.5149502 0.3971633 0.6327371         FALSE
6   a  B      3     6        6 0.5244519 0.4017140 0.6471899         FALSE
7   b  A      1    12       12 0.4784768 0.2581644 0.6987892         FALSE
8   b  A      2     6        6 0.5207987 0.3476214 0.6939760         FALSE
9   b  A      3     6        6 0.5495652 0.3789125 0.7202179         FALSE
10  b  B      1    12       12 0.4899329 0.3303875 0.6494783         FALSE
11  b  B      2     6        6 0.4754902 0.2782886 0.6726918         FALSE
12  b  B      3     6        6 0.4614122 0.3173339 0.6054904         FALSE
   runs.signal longest.run longest.run.max n.crossings n.crossings.min
1        FALSE           4               7           5               3
2        FALSE           2               6           3               1
3        FALSE           3               6           3               1
4        FALSE           3               7           8               3
5        FALSE           4               6           1               1
6        FALSE           2               6           4               1
7        FALSE           3               7           5               3
8        FALSE           4               6           1               1
9        FALSE           2               6           4               1
10       FALSE           3               7           7               3
11       FALSE           2               6           3               1
12       FALSE           3               6           3               1

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