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.06832944 
#>  sd   =  1.019868 
#> 
#> 
#> ── QC Rule 1: One Point is more than 3 Standard Deviations from the Mean ──
#> 
#> Violation on starting position:
#> [1] 140
#> Violation on starting value:
#> [1] 3.484544
#> 
#> ── QC Rule 2: 9 (or more) Points in a Row are on the Same Side of the Mean ──
#> 
#> Violation on starting positions:
#> [1] 101 102 103
#> Violation on starting values:
#> [1] 1.9725779 0.5163530 0.3810601
#> 
#> ── QC Rule 3: 6 (or more) Points in a Row are Continually Increasing or Decreasing ──
#> 
#> No violations
#> 
#> ── 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 ──
#> 
#> No violations
#> 
#> ── QC Rule 6: 4 Out of 5 Points in a Row are >1 Sd from the Mean ──
#> 
#> Violation on starting positions:
#> [1] 158 159
#> Violation on starting values:
#> [1] -0.1752581  1.7685515
#> 
#> ── QC Rule 7: >=15 Points in a Row are Within 1 Sd of the Mean ──
#> 
#> Violation on starting positions:
#> [1] 102 103
#> Violation on starting values:
#> [1] 0.5163530 0.3810601
#> 
#> ── 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  2.2288817     NA     NA     NA     NA     NA     NA     NA     NA
#> 2     2  1.0241989     NA     NA     NA     NA     NA     NA     NA     NA
#> 3     3  2.0587914     NA     NA     NA     NA     NA     NA     NA     NA
#> 4     4  0.8390369     NA     NA     NA     NA     NA     NA     NA     NA
#> 5     5 -0.1418048     NA     NA     NA     NA     NA     NA     NA     NA
#> 6     6 -0.3969623     NA     NA     NA     NA     NA     NA     NA     NA

if (FALSE) { # \dontrun{

library(plot2)
plot2(x, subtitle = "Workflow 'example123'")

} # }