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")

Source

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 .

Arguments

x

vector with values

m

mean

s

standard deviation

threshold

minimal number of sequential values before rule is triggered (defaults to Nelson's)

direction_mean

a logical to indicate whether n observations in a row must be tested for alternating in direction of the mean

rule

number of the rule

guideline

guideline of QC rules set, must be "Nelson", "Westgard", "AIAG", "Montgomery", or "Healthcare"

Rules list

RuleRule explanation:NelsonWestgardAIAGMontg.HC
#1One point is more than 3 standard deviations from the mean11111
#2n (or more) points in a row are on the same side of the mean99788
#3n (or more) points in a row are continually incr. or decr.6-666
#4n (or more) points in a row alternate in direction, incr. then decr.14-1414-
#5n - 1 out of n points in a row are >2 sd from the mean33333
#6n - 1 out of n points in a row are >1 sd from the mean5555-
#7>=n points in a row are within 1 sd of the mean15-151515
#8>=n points in a row outside 1 sd of the mean, in both directions8-88-

Montg.: Montgomery, HC: Healthcare

Examples

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'")

} # }