开发者

Accessing control chart results in R?

I have a short R script that loads a bunch of data and plots it in an XBar chart. Using the following 开发者_C百科code, I can plot the data and view the various statistical information.

library(qcc)
tir<-read.table("data.dat", header=T,,sep="\t")
names(tir)
attach(tir)
rand <- sample(tir)
xbarchart <- qcc(rand[1:100,],type="R")
summary(xbarchart)

I want to be able to do some process capability analysis (described here(PDF) on page 5) immediately after the XBar chart is created. In order to create the analysis chart, I need to store the LCL and UCL results from the XBar chart results created before as variables. Is there any way I can do this?


I shall answer your question using the example in the ?qcc help file.

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)

xbarchart <- qcc(x, type="xbar.one", std.dev = "SD")

A useful function to inspect the structure of variables and function results is str(), short for structure.

str(xbarchart)

List of 11
 $ call      : language qcc(data = x, type = "xbar.one", std.dev = "SD")
 $ type      : chr "xbar.one"
 $ data.name : chr "x"
 $ data      : num [1:15, 1] 33.8 33 34 33.8 33.5 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ Group  : chr [1:15] "1" "2" "3" "4" ...
  .. ..$ Samples: NULL
 $ statistics: Named num [1:15] 33.8 33 34 33.8 33.5 ...
  ..- attr(*, "names")= chr [1:15] "1" "2" "3" "4" ...
 $ sizes     : int [1:15] 1 1 1 1 1 1 1 1 1 1 ...
 $ center    : num 33.5
 $ std.dev   : num 0.342
 $ nsigmas   : num 3
 $ limits    : num [1, 1:2] 32.5 34.5
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr ""
  .. ..$ : chr [1:2] "LCL" "UCL"
 $ violations:List of 2
  ..$ beyond.limits : int(0) 
  ..$ violating.runs: num(0) 
 - attr(*, "class")= chr "qcc"

You will notice the second to last element in this list is called $limits and contains the two values for LCL and UCL.

It is simple to extract this element:

limits <- xbarchart$limits
limits

      LCL      UCL
 32.49855 34.54811

Thus LCL <- limits[1] and UCL <- limits[2]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜