Title: | Nelson Rules for Control Charts |
---|---|
Description: | Description: Rspc is an implementation of nelson rules for control charts in R. The Rspc package implements some Statistical Process Control methods, namely Levey-Jennings type of I (individuals) chart, Shewhart C (count) chart and Nelson rules. Typical workflow is taking the time series, specify the control limits, and list of Nelson rules you want to evaluate. There are several options how to modify the rules (one sided limits, numerical parameters of rules, etc.). Package is also capable of calculating the control limits from the data (so far only for i-chart and c-chart are implemented). |
Authors: | Martin Vagenknecht (MSD) [aut], Jindrich Soukup (MSD) [aut], Stanislav Matousek (MSD) [aut, cre], Janet Alvarado (MSD) [ctb, rev] |
Maintainer: | Stanislav Matousek <[email protected]> |
License: | GPL-3 |
Version: | 1.2.2 |
Built: | 2024-10-29 02:44:39 UTC |
Source: | https://github.com/merck/spc_package |
Evaluates whether to use custom limits or calculate them from the data.
CalculateLimits(x, lcl = NA, cl = NA, ucl = NA, type = "i", controlLimitDistance = 3)
CalculateLimits(x, lcl = NA, cl = NA, ucl = NA, type = "i", controlLimitDistance = 3)
x |
Numerical vector |
lcl |
Lower control limit, single value or NA |
cl |
Central line, single value or NA |
ucl |
Upper control limit, single value or NA |
type |
Type of control chart, either "i" for i-chart (default) or "c" for c-chart |
controlLimitDistance |
Multiple of st.dev to be used to calculate limits, possible values: 1, 2, 3 (default); this parameter affect the interpretation of lcl and ucl parameters |
If at least two limits were provided, the missing ones are calculated from the them. If one or zero limits were provided the rest is computed from data.
Named list with limits
CalculateLimits(x = rnorm(10), lcl = NA, cl = 100, ucl = NA, type = 'i')
CalculateLimits(x = rnorm(10), lcl = NA, cl = 100, ucl = NA, type = 'i')
Some Nelson rules uses so-called zones. This function calculates the borders of the zones for given limits.
CalculateZoneBorders(limits, controlLimitDistance = 3)
CalculateZoneBorders(limits, controlLimitDistance = 3)
limits |
List of limits provided by |
controlLimitDistance |
Multiple of st.dev to be used to calculate limits, possible values: 1, 2, 3 (default); this parameter affect the interpretation of lcl and ucl parameters |
Vector of zones
limits = CalculateLimits(x = rnorm(10), lcl = NA, cl = 100, ucl = NA, type = 'i') CalculateZoneBorders(limits) #limits is object created by CalculateLimits() function
limits = CalculateLimits(x = rnorm(10), lcl = NA, cl = 100, ucl = NA, type = 'i') CalculateZoneBorders(limits) #limits is object created by CalculateLimits() function
Evaluates the selected Nelson rules for a given numerical vector.
EvaluateRules(x, type = "i", whichRules = 1:8, lcl = NA, cl = NA, ucl = NA, controlLimitDistance = 3, returnAllSelectedRules = F, parRules = NULL)
EvaluateRules(x, type = "i", whichRules = 1:8, lcl = NA, cl = NA, ucl = NA, controlLimitDistance = 3, returnAllSelectedRules = F, parRules = NULL)
x |
Series to be evaluated, numerical vector |
type |
Type of control chart, either "i" for i-chart (default) or "c" for c-chart |
whichRules |
Selection of Nelson rules beeing evaluated, vector with numbers from 1 to 8 |
lcl |
Lower control limit, single numeric value (expected as mean - controlLimitDistance * sigma), if missing the function calculates it from data |
cl |
Central line, single numeric value (expected as mean), if missing the function calculates it from data |
ucl |
Upper control limit, single numeric value (expected as mean + controlLimitDistance * sigma), if missing the function calculates it from data |
controlLimitDistance |
Multiple of st.dev to be used to calculate limits, possible values: 1, 2, 3 (default); this parameter affect the interpretation of lcl and ucl parameters |
returnAllSelectedRules |
Resulting dataframe will contain all selected rules, either True or False, if missing only valid rules returned |
parRules |
Optional parameters for specific rules, for details see |
# Only Rules 1-4 relevant for c-chart.
# Check for non negative data for c-chart.
# For controlLimitDistance less than or equal to 2 disable rule 5.
# For controlLimitDistance less than or equal to 1 disable rule 5,6,8.
# For returnAllSelectedRules=TRUE columns of invalid rules for given evaluation are filled with NAs.
Dataframe containing original vector and rules evaluation
# Evaluate data, use all 8 Nelson rules, limits are specified by user EvaluateRules(x = rnorm(10), whichRules = 1:8, lcl = 0, cl = 50, ucl = 100) #Evaluate only rule 1, 3, 5, calculate limits from data using c-chart formula, #use 2 sigma instead of 3, modify default behaviour of rule by pars variable #created by function SetParameters() pars = SetParameters() EvaluateRules(x = rpois(10, lambda = 15), type = 'c', whichRules = c(1,3,5), lcl = NA, cl = NA, ucl = NA, controlLimitDistance = 2, parRules = pars) # pars is object of optional parameters created by SetParameters() function
# Evaluate data, use all 8 Nelson rules, limits are specified by user EvaluateRules(x = rnorm(10), whichRules = 1:8, lcl = 0, cl = 50, ucl = 100) #Evaluate only rule 1, 3, 5, calculate limits from data using c-chart formula, #use 2 sigma instead of 3, modify default behaviour of rule by pars variable #created by function SetParameters() pars = SetParameters() EvaluateRules(x = rpois(10, lambda = 15), type = 'c', whichRules = c(1,3,5), lcl = NA, cl = NA, ucl = NA, controlLimitDistance = 2, parRules = pars) # pars is object of optional parameters created by SetParameters() function
Auxiliary function to calling individual Rule functions.
NelsonRules(ruleN, data, zoneB, limits, parRules = NULL, ...)
NelsonRules(ruleN, data, zoneB, limits, parRules = NULL, ...)
ruleN |
Name of individual Rule function "Rule1" to "Rule8" |
data |
Data to be checked, numerical vector |
zoneB |
Vector of zones created by |
limits |
List of limit created by |
parRules |
List of optional parameters for this particular rule |
... |
unspecified arguments of a function |
Handling the missing values:
Missing values are represented by the symbol NA - not available.
Rule 1: NAs do not violate this rule.
Rule 2-8: NAs are ignored, they do not break Rule evaluation. NA values are removed from the vector, the rule function is calculated and then the NAs are returned back to it's original position in the vector.
Result of individual Rule function with predefined parameters
One point beyond the control limits
Rule1(x, lcl, ucl, sides, ...)
Rule1(x, lcl, ucl, sides, ...)
x |
Numerical vector |
lcl |
Lower control limit, single number |
ucl |
Upper control limit, single number |
sides |
Monitored side of the process: either "two-sided" (default), "upper" or "lower" |
... |
unspecified arguments of a function |
0 means: ok
1 means: violation
inequality used during evaluation
parametr sides is internally encoded as: 1 for "two-sided", 2 for "upper", 3 for "lower"
Vector of the same length as x
Rule1(x = rnorm(10), lcl = 10, ucl = 100, sides = "two-sided")
Rule1(x = rnorm(10), lcl = 10, ucl = 100, sides = "two-sided")
Nine points in a row are on one side of the central line.
Rule2(x, cl, nPoints = 9, ...)
Rule2(x, cl, nPoints = 9, ...)
x |
Numerical vector |
cl |
central line, single number |
nPoints |
Sequence of consequtive points to be evaluated |
... |
unspecified arguments of a function |
0 means: ok
1 means: violation
inequality used during evaluation
Vector of the same length as x
Rule2(x = rnorm(20), cl=0, nPoints = 9)
Rule2(x = rnorm(20), cl=0, nPoints = 9)
Six points in a row steadily increasing or decreasing.
Rule3(x, nPoints = 6, convention = 1, equalBreaksSeries = 1, ...)
Rule3(x, nPoints = 6, convention = 1, equalBreaksSeries = 1, ...)
x |
Numerical vector |
nPoints |
Sequence of consequtive points to be evaluated |
convention |
Calculation according to 'minitab' or 'jmp' (see details) |
equalBreaksSeries |
Equal values break consequtive series of points |
... |
unspecified arguments of a function |
0 means: ok
1 means: violation
parameter equalBreakSeries is internally encoded as: 1 for TRUE and 2 for FALSE
parameter convention is internally encoded as: 1 for 'minitab' and 2 for 'jmp'
Difference in convention parameter is as follows:
'minitab' - seven points in a row steadily increasing or decreasing
'jmp' - six points in a row steadily increasing or decreasing
Vector of the same length as x
Rule3(x = rnorm(20), nPoints = 6, convention = 1, equalBreaksSeries = 1)
Rule3(x = rnorm(20), nPoints = 6, convention = 1, equalBreaksSeries = 1)
Fourteen or more points in a row alternate in direction, increasing then decreasing.
Rule4(x, nPoints = 14, convention = 1, ...)
Rule4(x, nPoints = 14, convention = 1, ...)
x |
Numerical vector |
nPoints |
Sequence of consequtive points to be evaluated |
convention |
Calculation according to 'minitab' or 'jmp' (see details) |
... |
unspecified arguments of a function |
0 means: ok
1 means: violation
parameter convention is internally encoded as: 1 for 'minitab' and 2 for 'jmp'
Difference in convention parameter is as follows:
'minitab' - 15 or more points (14 changes of direction) in a row alternate in direction, increasing then decreasing
'jmp' - 14 or more points (13 changes of direction) in a row alternate in direction, increasing then decreasing
Vector of the same length as x
Rule4(x = rnorm(20), nPoints = 14,convention = 1)
Rule4(x = rnorm(20), nPoints = 14,convention = 1)
Two out of three consecutive points beyond the 2*sigma limits on same side of center line.
Rule5(x, zoneB, minNPoints = 2, nPoints = 3, ...)
Rule5(x, zoneB, minNPoints = 2, nPoints = 3, ...)
x |
Numerical vector |
zoneB |
Vector of zone borders |
minNPoints |
Minimal number of points in a sequence violating a rule |
nPoints |
Sequence of consequtive points to be evaluated |
... |
unspecified arguments of a function |
0 means: ok
1 means: violation
inequality used during evaluation
Rule is violated also if the first two points are beyond the 2*sigma limits
During calculation of EvaluateRules function wiht controlLimitDistance <= 2, the evaluation of this rule is suppressed
Vector of the same length as x
limits = CalculateLimits(x = rnorm(10), lcl = NA, cl = 100, ucl = NA, type = 'i') zones = CalculateZoneBorders(limits) Rule5(x = rnorm(20), zoneB = zones, minNPoints = 2, nPoints = 3) #zones is object created by function CalculateZoneBorders()
limits = CalculateLimits(x = rnorm(10), lcl = NA, cl = 100, ucl = NA, type = 'i') zones = CalculateZoneBorders(limits) Rule5(x = rnorm(20), zoneB = zones, minNPoints = 2, nPoints = 3) #zones is object created by function CalculateZoneBorders()
Four or five out of five points in a row are more than 1 standard deviation from the mean in the same direction.
Rule6(x, zoneB, minNPoints = 4, nPoints = 5, ...)
Rule6(x, zoneB, minNPoints = 4, nPoints = 5, ...)
x |
Numerical vector |
zoneB |
Vector of zone borders |
minNPoints |
Minimal number of points in a sequence violating a rule |
nPoints |
Sequence of consequtive points to be evaluated |
... |
unspecified arguments of a function |
0 means: ok
1 means: violation
inequality used during evaluation Rule is violated also if the first four points are beyond the 1 standard deviation from the mean During calculation of EvaluateRules function wiht controlLimitDistance <= 1, the evaluation of this rule is suppressed
Vector of the same length as x
limits = CalculateLimits(x = rnorm(10), lcl = NA, cl = 100, ucl = NA, type = 'i') zones = CalculateZoneBorders(limits) Rule6(x = rnorm(20), zoneB = zones, minNPoints = 4, nPoints = 5) #zones is object created by function CalculateZoneBorders()
limits = CalculateLimits(x = rnorm(10), lcl = NA, cl = 100, ucl = NA, type = 'i') zones = CalculateZoneBorders(limits) Rule6(x = rnorm(20), zoneB = zones, minNPoints = 4, nPoints = 5) #zones is object created by function CalculateZoneBorders()
Fifteen points in a row are all within 1 standard deviation of the mean on either side of the mean.
Rule7(x, nPoints = 15, zoneB, ...)
Rule7(x, nPoints = 15, zoneB, ...)
x |
Numerical vector |
nPoints |
Sequence of consequtive points to be evaluated |
zoneB |
Vector of zone borders |
... |
unspecified arguments of a function |
0 means: ok
1 means: violation
equality used during evaluation
Vector of the same length as x
limits = CalculateLimits(x = rnorm(10), lcl = NA, cl = 100, ucl = NA, type = 'i') zones = CalculateZoneBorders(limits) Rule7(x = rnorm(20), zoneB = zones, nPoints = 15) #zones is object created by function CalculateZoneBorders()
limits = CalculateLimits(x = rnorm(10), lcl = NA, cl = 100, ucl = NA, type = 'i') zones = CalculateZoneBorders(limits) Rule7(x = rnorm(20), zoneB = zones, nPoints = 15) #zones is object created by function CalculateZoneBorders()
Eight points in a row outside 1 standard deviation of the mean in both directions.
Rule8(x, nPoints = 8, zoneB, ...)
Rule8(x, nPoints = 8, zoneB, ...)
x |
Numerical vector |
nPoints |
Sequence of consequtive points to be evaluated |
zoneB |
Vector of zone borders |
... |
unspecified arguments of a function |
0 means: ok
1 means: violation
inequality used during evaluation During calculation of EvaluateRules function wiht controlLimitDistance <= 1, the evaluation of this rule is suppressed
Vector of the same length as x
limits = CalculateLimits(x = rnorm(10), lcl = NA, cl = 100, ucl = NA, type = 'i') zones = CalculateZoneBorders(limits) Rule8(x = rnorm(20), zoneB = zones, nPoints = 8) #zones is object created by function CalculateZoneBorders()
limits = CalculateLimits(x = rnorm(10), lcl = NA, cl = 100, ucl = NA, type = 'i') zones = CalculateZoneBorders(limits) Rule8(x = rnorm(20), zoneB = zones, nPoints = 8) #zones is object created by function CalculateZoneBorders()
Creates optional parameters with default settings.
SetParameters()
SetParameters()
The function is called without any parameter. If you want to modify any or the rules' setting, modify the result of this function and plug it to EvaluateRules
's parRules parameter.
List of optional parameters
pars <- SetParameters() pars$Rule1$sides <- "upper" #function doos not need any input parameters
pars <- SetParameters() pars$Rule1$sides <- "upper" #function doos not need any input parameters