使用 R 和 qcc 实施额外的标准 运行 规则

Implementing additional standard run rules with R and qcc

我是 R 的新手,想了解它可以为控制图做些什么。我已经阅读了关于 qcc 的文章,并根据我自己的数据集在 R studio 中创建了示例图表以生成图形或只是底层数据。

似乎在 QCC 中实现了 shewhart control/run 规则中的两个(+/- 3 西格玛和一个字符串 above/below 中心),但更多已被定义并经常用于实践。 e.g. Nelson rules

是否有实现这些的 R library/function?除了实施规则,我还想支持指定与规则相关的 "constant" 的选项。例如,所引用的文章说 "Eight points in a row.." 我想将八作为参数。我认为 qcc 命令的 $data 输出可以作为参数传递(连同规则向量 "constant" 选项),并且在 return 中将是违规点列表和规则编号违反了。

有什么想法/建议吗?

我们正致力于在 R 中实施 Nelson Rules。我认为这正是您正在寻找的(很高兴分享,我在互联网上的其他任何地方都找不到 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)
}

For example where the referenced article says "Eight points in a row.." I would like eight to be a parameter.

在某些函数中,这也是对参数 minrun 的作用。