These rules are used for quality control (QC). Default values are set for Nelson's QC rules, but they also support Westgard, AIAG, Montgomery and Healthcare QC rules.
qc_rule1(x, m = mean(x), s = sd(x))
qc_rule2(x, m = mean(x), threshold = 9)
qc_rule3(x, threshold = 6)
qc_rule4(x, m = mean(x), threshold = 14, direction_mean = FALSE)
qc_rule5(x, m = mean(x), s = sd(x), threshold = 3)
qc_rule6(x, m = mean(x), s = sd(x), threshold = 5)
qc_rule7(x, m = mean(x), s = sd(x), threshold = 15)
qc_rule8(x, m = mean(x), s = sd(x), threshold = 8)
qc_rule_text(rule, threshold)
qc_test(x, m = mean(x), s = sd(x), guideline = "Nelson")
Nelson LS. The Shewhart Control Chart—Tests for Special Causes. Journal of Quality Technology. Informa UK Limited; 1984 Oct;16(4):237–9. doi:10.1080/00224065.1984.11978921 .
vector with values
mean
standard deviation
minimal number of sequential values before rule is triggered (defaults to Nelson's)
a logical to indicate whether n observations in a row must be tested for alternating in direction of the mean
number of the rule
guideline of QC rules set, must be "Nelson"
, "Westgard"
, "AIAG"
, "Montgomery"
, or "Healthcare"
Rule | Rule explanation: | Nelson | Westgard | AIAG | Montg. | HC |
#1 | One point is more than 3 standard deviations from the mean | 1 | 1 | 1 | 1 | 1 |
#2 | n (or more) points in a row are on the same side of the mean | 9 | 9 | 7 | 8 | 8 |
#3 | n (or more) points in a row are continually incr. or decr. | 6 | - | 6 | 6 | 6 |
#4 | n (or more) points in a row alternate in direction, incr. then decr. | 14 | - | 14 | 14 | - |
#5 | n - 1 out of n points in a row are >2 sd from the mean | 3 | 3 | 3 | 3 | 3 |
#6 | n - 1 out of n points in a row are >1 sd from the mean | 5 | 5 | 5 | 5 | - |
#7 | >=n points in a row are within 1 sd of the mean | 15 | - | 15 | 15 | 15 |
#8 | >=n points in a row outside 1 sd of the mean, in both directions | 8 | - | 8 | 8 | - |
Montg.: Montgomery, HC: Healthcare
x <- qc_test(rnorm(250))
x
#>
#> ── Quality Control Rules According to Nelson ───────────────────────────────────
#> n = 250
#> mean = -0.02474295
#> sd = 0.9929438
#>
#>
#> ── QC Rule 1: One Point is more than 3 Standard Deviations from the Mean ──
#>
#> Violation on starting position:
#> [1] 188
#> Violation on starting value:
#> [1] -3.429538
#>
#> ── QC Rule 2: 9 (or more) Points in a Row are on the Same Side of the Mean ──
#>
#> Violation on starting positions:
#> [1] 180 208
#> Violation on starting values:
#> [1] -0.2157856 -0.5220783
#>
#> ── QC Rule 3: 6 (or more) Points in a Row are Continually Increasing or Decreasing ──
#>
#> Violation on starting positions:
#> [1] 65 179
#> Violation on starting values:
#> [1] -1.3449661 0.5478168
#>
#> ── QC Rule 4: 14 (or more) Points in a Row Alternate in Direction, Increasing then Decreasing ──
#>
#> No violations
#>
#> ── QC Rule 5: 2 Out of 3 Points in a Row are >2 Sd from the Mean ──
#>
#> Violation on starting positions:
#> [1] 242 243 244
#> Violation on starting values:
#> [1] 0.2951258 2.3358788 2.1305115
#>
#> ── QC Rule 6: 4 Out of 5 Points in a Row are >1 Sd from the Mean ──
#>
#> No violations
#>
#> ── QC Rule 7: >=15 Points in a Row are Within 1 Sd of the Mean ──
#>
#> No violations
#>
#> ── QC Rule 8: >=8 Points in a Row Outside 1 Sd of the Mean, in both Directions ──
#>
#> No violations
# turn into data.frame, e.g. for export
head(as.data.frame(x))
#> index value rule_1 rule_2 rule_3 rule_4 rule_5 rule_6 rule_7 rule_8
#> 1 1 0.1749773 NA NA NA NA NA NA NA NA
#> 2 2 0.6706815 NA NA NA NA NA NA NA NA
#> 3 3 0.3610765 NA NA NA NA NA NA NA NA
#> 4 4 -0.4413918 NA NA NA NA NA NA NA NA
#> 5 5 0.5406807 NA NA NA NA NA NA NA NA
#> 6 6 -0.3846880 NA NA NA NA NA NA NA NA
if (FALSE) { # \dontrun{
library(plot2)
plot2(x, subtitle = "Workflow 'example123'")
} # }