2015-06-20 78 views
1

我是一个R新手,并且想了解它可以为控制图表做些什么。我已经阅读了关于qcc的文章,并根据我自己的数据集在R studio中创建了示例图表以生成图形或简单的底层数据。使用R和qcc实现额外的标准运行规则

似乎有两个shewhart控制/运行规则在QCC中实现(+/- 3 sigma和字符串在中心上方/下方),但更多已定义并且在实践中经常使用。 e.g. Nelson rules

是否有R库/函数实现这些?除了实施规则之外,我想支持指定与规则相关的“常量”的选项。例如,参考文章中提到“连续八个点”。我希望八个参数。我在想,qcc命令的$ data输出可以作为参数传递(以及规则“常量”选项的向量),并返回违反点和违反规则的列表。

有什么想法/建议吗?

+0

那么,一个建议是使用'ggplot2'软件包,它使您可以更好地控制图表。 – Bernardo

+0

嗨贝尔纳多,感谢您的建议,但我并不真正寻求更好的控制图形。我正在寻找功能来实现全部8个Nelson/AT&T运行规则和参数。 – John

回答

0

在我的博士学位,我与医学微生物学家和serologist工作沿着我们在各自工作R.纳尔逊规则的实施

我想,这正是你要寻找的(幸福分享,我无法找到的R实现其他地方在互联网上):

nelsonr1 <- function(x, m = mean(x), s = sd(x)) { 
    # Nelson's QC rule 1: detect values outside + or -3 sd 
    which(abs((x - m)/s) >= 3) 
} 

nelsonr2 <- function(x, m = mean(x), minrun = 9) { 
    # Nelson's QC rule 2: detect runs of >= 9 points on the same side of the mean 
    n <- length(x) 
    counts <- sign(x - m) 
    result <- counts 
    for (runlength in 2:minrun) 
     result <- result + c(counts[runlength:n], rep(0, runlength - 1)) 
    which(abs(result) >= minrun) 
} 

nelsonr3 <- function(x, minrun = 6) { 
    # Nelson's QC rule 3: detect strict increase or decrease in >= 6 points in a row 
    # Between 6 points you have 5 instances of increasing or decreasing. Therefore minrun - 1. 
    n <- length(x) 
    signs <- sign(c(x[-1], x[n]) - x) 
    counts <- signs 
    for (rl in 2:(minrun - 1)) { 
     counts <- counts + c(signs[rl:n], rep(0, rl - 1)) 
    } 
    which(abs(counts) >= minrun - 1) 
} 

nelsonr4 <- function(x, m = mean(x), minrun = 14, directing_from_mean = FALSE) { 
    # Nelson's QC rule 4: 14 points in a row alternating in direction from the mean, 
    # or 14 points in a row alternating in increase and decrease 
    n <- length(x) 
    if (directing_from_mean == TRUE) { 
     signs <- sign(x - m) 
    } else { 
     signs <- sign(c(x[-1],x[n]) - x) 
    } 
    counts <- signs 
    fac <- -1 
    for (rl in 2:minrun) { 
     counts <- counts + fac * c(signs[rl:n], rep(0, rl - 1)) 
     fac <- -fac 
    } 
    counts <- abs(counts) 
    which(counts >= minrun) 
} 

nelsonr5 <- function(x, m = mean(x), s = sd(x), minrun = 3) { 
    # Nelson's QC rule 5: two out of 3 >2 sd from mean in the same direction 
    n <- length(x) 
    pos <- 1 * ((x - m)/s > 2) 
    neg <- 1 * ((x - m)/s < -2) 
    poscounts <- pos 
    negcounts <- neg 
    for (rl in 2:minrun) { 
     poscounts <- poscounts + c(pos[rl:n], rep(0, rl - 1)) 
     negcounts <- negcounts + c(neg[rl:n], rep(0, rl - 1)) 
    } 
    counts <- apply(cbind(poscounts, negcounts), 1, max) 
    which(counts >= minrun -1) 
} 

nelsonr6 <- function(x, m = mean(x), s = sd(x), minrun = 5) { 
    # Nelson's QC rule 6: four out of five > 1 sd from mean in the same direction 
    n <- length(x) 
    pos <- 1 * ((x - m)/s > 1) 
    neg <- 1 * ((x - m)/s < -1) 
    poscounts <- pos 
    negcounts <- neg 
    for (rl in 2:minrun) { 
     poscounts <- poscounts + c(pos[rl:n], rep(0, rl - 1)) 
     negcounts <- negcounts + c(neg[rl:n], rep(0, rl - 1)) 
    } 
    counts <- apply(cbind(poscounts, negcounts), 1, max) 
    which(counts >= minrun - 1) 
} 

nelsonr7 <- function(x, m = mean(x), s = sd(x), minrun = 15) { 
    # Nelson's QC rule 7: >= 15 points in a row within 1 sd from the mean 
    n <- length(x) 
    within <- 1 * (abs((x - m)/s) < 1) 
    counts <- within 
    for (rl in 2:minrun) 
     counts <- counts + c(within[rl:n], rep(0, rl - 1)) 
    which(counts >= minrun) 
} 

nelsonr8 <- function(x, m = mean(x), s = sd(x), minrun = 8) { 
    # Nelson's QC rule 8: >= 8 points in a row all outside the m + -1s range 
    n <- length(x) 
    outofrange <- 1 * (abs((x - m)/s) > 1) 
    counts <- outofrange 
    for (rl in 2:minrun) 
     counts <- counts + c(outofrange[rl:n], rep(0, rl - 1)) 
    which(counts >= minrun) 
} 

例如引用的文章说,其中“八分在一排。”我想八是参数。

在某些功能中,这也是与参数minrun一样。

+0

在发布上述内容之后,我实际上停止追求R,因为它不支持这些规则。这可能会重新打开我的项目未来版本的选项。关于应用统计的一个评论 - 我认为sd(x)是结果集的总体标准偏差,通常不会用在控制图中。相反,如果实际值未知,则根据某些先前点的中值或平均移动范围进行确定性估计。这些值有时可能根本不同。可能对你的研究很重要? – John

+0

这是真的,这就是为什么sd(x)是一个参数。你可以在任何你喜欢的地方使用自己的东西。我也使用均值作为参数,因为现在它使用算术平均值,但可以使用几何或调和均值。我自己使用EWMA作为移动平均线。如果我是你,我肯定会回到R :)尝试RStudio,这是一个非常非常好的与R一起工作的方式。 –

+0

我认为我的语法是你的问题的答案。如果你也这么想,请将其标记为答案。谢谢! –