qcc: Quality Control Charts

Description Usage Arguments Value Note Author(s) References See Also Examples

View source: R/qcc.R

Description

Create an object of class 'qcc' to perform statistical quality control. This object may then be used to plot Shewhart charts, drawing OC curves, computes capability indices, and more.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
qcc(data, type, sizes, center, std.dev, limits,
    data.name, labels, newdata, newsizes, newdata.name,
    newlabels, nsigmas = 3, confidence.level,
    rules = shewhart.rules, plot = TRUE, ...)

## S3 method for class 'qcc'
print(x, ...)

## S3 method for class 'qcc'
summary(object, digits = getOption("digits"), ...)

## S3 method for class 'qcc'
plot(x, add.stats = TRUE, chart.all = TRUE, 
     label.limits = c("LCL ", "UCL"), title, xlab, ylab, ylim, 
     axes.las = 0, digits = getOption("digits"),
     restore.par = TRUE, ...)

Arguments

data

a data frame, a matrix or a vector containing observed data for the variable to chart. Each row of a data frame or a matrix, and each value of a vector, refers to a sample or ”rationale group”.

type

a character string specifying the group statistics to compute.
Available methods are:

Statistic charted Chart description
"xbar" mean means of a continuous process variable
"R" range ranges of a continuous process variable
"S" standard deviation standard deviations of a continuous variable
"xbar.one" mean one-at-time data of a continuous process variable
"p" proportion proportion of nonconforming units
"np" count number of nonconforming units
"c" count nonconformities per unit
"u" count average nonconformities per unit
"g" count number of non-events between events

Furthermore, a user specified type of chart, say "newchart", can be provided. This requires the definition of "stats.newchart", "sd.newchart", and "limits.newchart". As an example, see stats.xbar.

sizes

a value or a vector of values specifying the sample sizes associated with each group. For continuous data provided as data frame or matrix the sample sizes are obtained counting the non-NA elements of each row. For "p", "np" and "u" charts the argument sizes is required.

center

a value specifying the center of group statistics or the ”target” value of the process.

std.dev

a value or an available method specifying the within-group standard deviation(s) of the process.
Several methods are available for estimating the standard deviation in case of a continuous process variable; see sd.xbar, sd.xbar.one, sd.R, sd.S.

limits

a two-values vector specifying control limits.

data.name

a string specifying the name of the variable which appears on the plots. If not provided is taken from the object given as data.

labels

a character vector of labels for each group.

newdata

a data frame, matrix or vector, as for the data argument, providing further data to plot but not included in the computations.

newsizes

a vector as for the sizes argument providing further data sizes to plot but not included in the computations.

newdata.name

a string specifying the name of the variable which appears on the plots. If not provided is taken from the object given as newdata.

newlabels

a character vector of labels for each new group defined in the argument newdata.

nsigmas

a numeric value specifying the number of sigmas to use for computing control limits. It is ignored when the confidence.level argument is provided.

confidence.level

a numeric value between 0 and 1 specifying the confidence level of the computed probability limits.

rules

a function of rules to apply to the chart. By default, the shewhart.rules function is used.

plot

logical. If TRUE a Shewhart chart is plotted.

add.stats

a logical value indicating whether statistics and other information should be printed at the bottom of the chart.

chart.all

a logical value indicating whether both statistics for data and for newdata (if given) should be plotted.

label.limits

a character vector specifying the labels for control limits.

title

a string giving the label for the main title.

xlab

a string giving the label for the x-axis.

ylab

a string giving the label for the y-axis.

ylim

a numeric vector specifying the limits for the y-axis.

axes.las

numeric in {0,1,2,3} specifying the style of axis labels. See help(par).

digits

the number of significant digits to use.

restore.par

a logical value indicating whether the previous par settings must be restored. If you need to add points, lines, etc. to a control chart set this to FALSE.

object

an object of class 'qcc'.

x

an object of class 'qcc'.

...

additional arguments to be passed to the generic function.

Value

Returns an object of class 'qcc'.

Note

For a nice blog post discussing the qcc package, in particular how to implement the Western Eletric Rules (WER), see http://blog.yhathq.com/posts/quality-control-in-r.html.

Author(s)

Luca Scrucca

References

Mason, R.L. and Young, J.C. (2002) Multivariate Statistical Process Control with Industrial Applications, SIAM.
Montgomery, D.C. (2005) Introduction to Statistical Quality Control, 5th ed. New York: John Wiley & Sons.
Ryan, T. P. (2000), Statistical Methods for Quality Improvement, 2nd ed. New York: John Wiley & Sons, Inc.
Scrucca, L. (2004). qcc: an R package for quality control charting and statistical process control. R News 4/1, 11-17.
Wetherill, G.B. and Brown, D.W. (1991) Statistical Process Control. New York: Chapman & Hall.

See Also

shewhart.rules, cusum, ewma, oc.curves, process.capability, qcc.groups

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
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
##
##  Continuous data 
##
data(pistonrings)
attach(pistonrings)
diameter <- qcc.groups(diameter, sample)

qcc(diameter[1:25,], type="xbar")
qcc(diameter[1:25,], type="xbar", newdata=diameter[26:40,])
q <- qcc(diameter[1:25,], type="xbar", newdata=diameter[26:40,], plot=FALSE)
plot(q, chart.all=FALSE)
qcc(diameter[1:25,], type="xbar", newdata=diameter[26:40,], nsigmas=2)
qcc(diameter[1:25,], type="xbar", newdata=diameter[26:40,], confidence.level=0.99)

qcc(diameter[1:25,], type="R")
qcc(diameter[1:25,], type="R", newdata=diameter[26:40,])

qcc(diameter[1:25,], type="S")
qcc(diameter[1:25,], type="S", newdata=diameter[26:40,])

# add warning limits at 2 std. deviations
q <- qcc(diameter[1:25,], type="xbar", newdata=diameter[26:40,], plot=FALSE)
(warn.limits <- limits.xbar(q$center, q$std.dev, q$sizes, 2))
plot(q, restore.par = FALSE)
abline(h = warn.limits, lty = 3, col = "chocolate")

# variable control limits
out <- c(9, 10, 30, 35, 45, 64, 65, 74, 75, 85, 99, 100)
diameter <- qcc.groups(pistonrings$diameter[-out], sample[-out])
qcc(diameter[1:25,], type="xbar")
qcc(diameter[1:25,], type="R")
qcc(diameter[1:25,], type="S")
qcc(diameter[1:25,], type="xbar", newdata=diameter[26:40,])
qcc(diameter[1:25,], type="R", newdata=diameter[26:40,])
qcc(diameter[1:25,], type="S", newdata=diameter[26:40,])

detach(pistonrings)

##
##  Attribute data 
##

data(orangejuice)
attach(orangejuice)
qcc(D[trial], sizes=size[trial], type="p")

# remove out-of-control points (see help(orangejuice) for the reasons)
inc <- setdiff(which(trial), c(15,23))
q1 <- qcc(D[inc], sizes=size[inc], type="p")
qcc(D[inc], sizes=size[inc], type="p", newdata=D[!trial], newsizes=size[!trial]) 
detach(orangejuice)

data(orangejuice2)
attach(orangejuice2)
names(D) <- sample
qcc(D[trial], sizes=size[trial], type="p")
q2 <- qcc(D[trial], sizes=size[trial], type="p", newdata=D[!trial], newsizes=size[!trial])
detach(orangejuice2)

# put on the same graph the two orange juice samples
oldpar <- par(no.readonly = TRUE)
par(mfrow=c(1,2), mar=c(5,5,3,0))
plot(q1, title="First samples", ylim=c(0,0.5), add.stats=FALSE, restore.par=FALSE)
par("mar"=c(5,0,3,3), yaxt="n")
plot(q2, title="Second samples", add.stats=FALSE, ylim=c(0,0.5))
par(oldpar)

data(circuit)
attach(circuit)
qcc(x[trial], sizes=size[trial], type="c")
# remove out-of-control points (see help(circuit) for the reasons)
inc <- setdiff(which(trial), c(6,20))
qcc(x[inc], sizes=size[inc], type="c", labels=inc)
qcc(x[inc], sizes=size[inc], type="c", labels=inc, 
    newdata=x[!trial], newsizes=size[!trial], newlabels=which(!trial))
qcc(x[inc], sizes=size[inc], type="u", labels=inc, 
    newdata=x[!trial], newsizes=size[!trial], newlabels=which(!trial))
detach(circuit)

data(pcmanufact)
attach(pcmanufact)
qcc(x, sizes=size, type="u")
detach(pcmanufact)

data(dyedcloth)
attach(dyedcloth)
qcc(x, sizes=size, type="u")
# standardized control chart
q <- qcc(x, sizes=size, type="u", plot=FALSE)
z <- (q$statistics - q$center)/sqrt(q$center/q$size)
plot(z,  type="o", ylim=range(z,3,-3), pch=16)
abline(h=0, lty=2)
abline(h=c(-3,3), lty=2)
detach(dyedcloth)

##
##  Continuous one-at-time data 
##

# viscosity data (Montgomery, pag. 242)
x <- c(33.75, 33.05, 34, 33.81, 33.46, 34.02, 33.68, 33.27, 33.49, 33.20,
       33.62, 33.00, 33.54, 33.12, 33.84)
qcc(x, type="xbar.one")
qcc(x, type="xbar.one", std.dev = "SD")

Example output

Package 'qcc' version 2.7
Type 'citation("qcc")' for citing this R package in publications.
List of 11
 $ call      : language qcc(data = diameter[1:25, ], type = "xbar")
 $ type      : chr "xbar"
 $ data.name : chr "diameter[1:25, ]"
 $ data      : num [1:25, 1:5] 74 74 74 74 74 ...
  ..- attr(*, "dimnames")=List of 2
 $ statistics: Named num [1:25] 74 74 74 74 74 ...
  ..- attr(*, "names")= chr [1:25] "1" "2" "3" "4" ...
 $ sizes     : Named int [1:25] 5 5 5 5 5 5 5 5 5 5 ...
  ..- attr(*, "names")= chr [1:25] "1" "2" "3" "4" ...
 $ center    : num 74
 $ std.dev   : num 0.00979
 $ nsigmas   : num 3
 $ limits    : num [1, 1:2] 74 74