| Title: | Acceptance Sampling Plans Design |
|---|---|
| Description: | Provides tools for designing and analyzing Acceptance Sampling plans. Supports both Attributes Sampling (Binomial and Poisson distributions) and Variables Sampling (Normal and Beta distributions), enabling quality control for fractional and compositional data. Uses nonlinear programming for sampling plan optimization, minimizing sample size while controlling producer's and consumer's risks. Operating Characteristic curves are available for plan visualization. |
| Authors: | Ha Truong [aut, cre, cph], Victor Miranda [ths, rev], Roger Kissling [ths, rev] |
| Maintainer: | Ha Truong <[email protected]> |
| License: | GPL-3 |
| Version: | 0.0.8 |
| Built: | 2026-05-21 08:13:15 UTC |
| Source: | https://github.com/vietha/accsamplingdesign |
Calculate the probability of acceptance for a given quality level.
accProb(plan, p)accProb(plan, p)
plan |
Acceptance plan object ( |
p |
True quality level (proportion of nonconforming). |
Numeric probability between 0 and 1.
Ha Truong
# Example for attribute plan attr_plan <- optAttrPlan(PRQ = 0.01, CRQ = 0.1) accProb(attr_plan, 0.05) # Example for variable plan (normal distribution) var_plan <- optVarPlan( PRQ = 0.025, # Acceptable quality level (% nonconforming) CRQ = 0.1, # Rejectable quality level (% nonconforming) alpha = 0.05, # Producer's risk beta = 0.1, # Consumer's risk distribution = "normal" ) accProb(var_plan, 0.05)# Example for attribute plan attr_plan <- optAttrPlan(PRQ = 0.01, CRQ = 0.1) accProb(attr_plan, 0.05) # Example for variable plan (normal distribution) var_plan <- optVarPlan( PRQ = 0.025, # Acceptable quality level (% nonconforming) CRQ = 0.1, # Rejectable quality level (% nonconforming) alpha = 0.05, # Producer's risk beta = 0.1, # Consumer's risk distribution = "normal" ) accProb(var_plan, 0.05)
Constructs an AttrPlan or VarPlan object from the given parameters.
manualPlan(distribution = c("binomial", "poisson", "normal", "beta"), n = NULL, c = NULL, k = NULL, USL = NULL, LSL = NULL, sigma = NULL, theta = NULL, sigma_type = c("known", "unknown"), theta_type = c("known", "unknown"))manualPlan(distribution = c("binomial", "poisson", "normal", "beta"), n = NULL, c = NULL, k = NULL, USL = NULL, LSL = NULL, sigma = NULL, theta = NULL, sigma_type = c("known", "unknown"), theta_type = c("known", "unknown"))
distribution |
One of |
n |
Sample size. |
c |
Acceptance number (for attribute sampling). |
k |
Acceptability constant (for variable sampling). |
USL |
Upper specification limit. |
LSL |
Lower specification limit. |
sigma |
Standard deviation (for normal plans). |
theta |
Precision parameter (for beta plans). |
sigma_type |
Either |
theta_type |
Either |
This function provides a user-friendly wrapper to construct AS plan directly
from parameters.
Internally, it constructs the appropriate AttrPlan or VarPlan,
from given paramenters.
An object of class "AttrPlan" or VarPlan.
Ha Truong
# Attribute sampling with user-defined parameters plan1 <- manualPlan(n = 100, c = 2, distribution = "binomial") # Variable sampling (normal) plan2 <- manualPlan(n = 30, k = 1.5, distribution = "normal", USL = 10, sigma = 1)# Attribute sampling with user-defined parameters plan1 <- manualPlan(n = 100, c = 2, distribution = "binomial") # Variable sampling (normal) plan2 <- manualPlan(n = 30, k = 1.5, distribution = "normal", USL = 10, sigma = 1)
Based on Specification Limits and ProbabilityComputes the estimated mean for a given level of quality and specification limit under either a normal or beta distribution.
muEst(p, USL = NULL, LSL = NULL, sigma = NULL, theta = NULL, dist = c("normal", "beta"))muEst(p, USL = NULL, LSL = NULL, sigma = NULL, theta = NULL, dist = c("normal", "beta"))
p |
Level of quality (numeric, between 0 and 1). |
USL |
Upper specification limit (numeric). Only one of |
LSL |
Lower specification limit (numeric). Only one of |
sigma |
Standard deviation (numeric) for the normal distribution. Must be provided if |
theta |
Theta parameter (numeric) for the beta distribution. Must be provided if |
dist |
Distribution type. Either |
The function estimates the mean corresponding to a given tail probability p, assuming that the process output follows either a normal or beta distribution, and that the probability of being beyond the provided specification limit equals 1 - p.
For the normal distribution, the mean is calculated using the inverse cumulative distribution function (quantile function) of the normal distribution.
For the beta distribution, the mean is solved numerically such that the CDF at the specified limit equals p, given the shape determined by theta.
Exactly one of USL or LSL must be provided to define whether the probability refers to the upper or lower tail.
Returns the estimated mean as a numeric value.
Ha Truong
# Example for normal distribution with lower specification limit (LSL) muEst(p = 0.95, LSL = 10, sigma = 2, dist = "normal") # Example for beta distribution with upper specification limit (USL) muEst(p = 0.95, USL = 0.7, theta = 500, dist = "beta")# Example for normal distribution with lower specification limit (LSL) muEst(p = 0.95, LSL = 10, sigma = 2, dist = "normal") # Example for beta distribution with upper specification limit (USL) muEst(p = 0.95, USL = 0.7, theta = 500, dist = "beta")
Generic function to compute Operating Characteristic (OC) curve data from an acceptance sampling plan.
OCdata(plan, pd = NULL)OCdata(plan, pd = NULL)
plan |
An object of class |
pd |
Vector of quality levels (proportions of nonconforming items). |
This is a generic function. Methods are defined for objects of class
AttrPlan and VarPlan, which compute the probability of
acceptance across a range of quality levels (proportions of nonconforming).
See OCdata.AttrPlan and OCdata.VarPlan for details.
An object of class "OCdata", a list containing:
pd — quality levels (e.g. proportion defective)
paccept — probability of acceptance at each level
process_means — process means, if applicable
dist, n, k, c — plan parameters
Ha Truong
Designs Attributes Acceptance Sampling plans using producer/consumer risk criteria.
optAttrPlan(PRQ, CRQ, alpha = 0.05, beta = 0.10, distribution = c("binomial", "poisson"))optAttrPlan(PRQ, CRQ, alpha = 0.05, beta = 0.10, distribution = c("binomial", "poisson"))
PRQ |
Producer Risk Quality (0 < PRQ < 1) |
CRQ |
Consumer Risk Quality (PRQ < CRQ < 1) |
alpha |
Producer's risk (0.05 default) |
beta |
Consumer's risk (0.10 default) |
distribution |
Support binomial and poisson distribution |
AttrPlan object containing:
n |
Sample size |
c |
Acceptance number |
PRQ |
Input PRQ value |
CRQ |
Input CRQ value |
distribution |
Selected distribution |
Ha Truong
ISO 2859-1:1999 - Sampling procedures for inspection by attributes
Schilling, E.G., & Neubauer, D.V. (2017). Acceptance Sampling in Quality Control (3rd ed.). Chapman and Hall/CRC. https://doi.org/10.4324/9781315120744
plan <- optAttrPlan(PRQ = 0.01, CRQ = 0.1, alpha = 0.05, beta = 0.1, distribution = "binomial")plan <- optAttrPlan(PRQ = 0.01, CRQ = 0.1, alpha = 0.05, beta = 0.1, distribution = "binomial")
Design optimal variable acceptance sampling plans based on specified parameters. Supports different distributions (binomial, poisson, normal, beta) and accommodates known or unknown standard deviation and process parameters.
optPlan(PRQ, CRQ, alpha = 0.05, beta = 0.10, USL = NULL, LSL = NULL, distribution = c("binomial", "poisson", "normal", "beta"), sigma_type = c("known", "unknown"), theta_type = c("known", "unknown"), sigma = NULL, theta = NULL)optPlan(PRQ, CRQ, alpha = 0.05, beta = 0.10, USL = NULL, LSL = NULL, distribution = c("binomial", "poisson", "normal", "beta"), sigma_type = c("known", "unknown"), theta_type = c("known", "unknown"), sigma = NULL, theta = NULL)
PRQ |
Producer's risk quality level (e.g., acceptable quality level). |
CRQ |
Consumer's risk quality level (e.g., rejectable quality level). |
alpha |
Producer's risk (Type I error), default is 0.05. |
beta |
Consumer's risk (Type II error), default is 0.10. |
USL |
Upper Specification Limit. Required for variable sampling plans. |
LSL |
Lower Specification Limit. Required for variable sampling plans. |
distribution |
Distribution type used in the plan. Can be |
sigma_type |
Indicates if the standard deviation ( |
theta_type |
Indicates if the process parameter ( |
sigma |
Known standard deviation of the process, if applicable. |
theta |
Precision (dispersion) parameter for the beta distribution.
If unknown, it can be estimated from historical data using functions such as |
This function designs optimal acceptance sampling plans by balancing producer's and consumer's risks under specified quality levels. It supports plans for attributes (binomial) and variables (normal or beta distributions), including cases with unknown standard deviation or distributional parameters.
For the "normal" model, the plan can be computed assuming the standard deviation
(sigma) is either known or estimated from data. Optimization for unknown sigma
is performed using the derivative-free Nelder-Mead method (Nelder and Mead, 1965) via
optim in base R.
For the "beta" model, the dispersion (precision) parameter theta determines
how concentrated the distribution is around the mean. Users must either:
provide a known value for theta, typically obtained from prior process studies or historical data; or
estimate it from sample data using a fitting function such as betaff in the VGAM package.
Optimization for Beta plans is performed using optim with the "L-BFGS-B" method
(Byrd et al., 1995) to handle bounds on sample size and acceptance numbers.
This approach ensures stable and efficient plan calculation while relying solely on base R functionality.
Returns a list or data frame with optimal sample size(s) and critical value(s) based on the specified parameters and distribution.
distribution |
Selected distribution |
sample_size |
Final sample size after rounding up to the next integer, for practical application. |
n |
Sample size (unrounded for Variables Acceptance Sampling). |
k |
Acceptability constant - For Variables Acceptance Sampling. |
c |
Acceptance number - For Attributes Acceptance Sampling. |
Ha Truong
* ISO 2859-1:1999 - Sampling procedures for inspection by attributes
* ISO 3951-1:2013 - Sampling procedures for inspection by variables.
* Wilrich, PT. (2004). Single Sampling Plans for Inspection by Variables under a Variance Component Situation. In: Lenz, HJ., Wilrich, PT. (eds) Frontiers in Statistical Quality Control 7. Physica, Heidelberg.
* K. Govindaraju and R. Kissling (2015). Sampling plans for Beta-distributed compositional fractions.
* J. A. Nelder and R. Mead. A simplex method for function minimization. The Computer Journal, 7(4): 308–313, 1965. DOI 10.1093/comjnl/7.4.308.
* R. H. Byrd, P. Lu, J. Nocedal and C. Zhu. A limited memory algorithm for bound constrained optimization. SIAM Journal on Scientific Computing, 16(5): 1190–1208, 1995. DOI 10.1137/0916069.
# Example usage (normal distribution, known sigma): optPlan(PRQ = 0.005, CRQ = 0.03, alpha = 0.05, beta = 0.10, distribution = "normal", sigma_type = "known") # Example usage (beta distribution, unknown theta): optPlan(PRQ = 0.025, CRQ = 0.10, alpha = 0.05, beta = 0.10, distribution = "beta", theta = 6.6e8, theta_type = "unknown", LSL = 5.65e-6)# Example usage (normal distribution, known sigma): optPlan(PRQ = 0.005, CRQ = 0.03, alpha = 0.05, beta = 0.10, distribution = "normal", sigma_type = "known") # Example usage (beta distribution, unknown theta): optPlan(PRQ = 0.025, CRQ = 0.10, alpha = 0.05, beta = 0.10, distribution = "beta", theta = 6.6e8, theta_type = "unknown", LSL = 5.65e-6)
Creates Variable Acceptance Sampling plans for normal or beta distributed measurements.
optVarPlan(PRQ, CRQ, alpha = 0.05, beta = 0.10, USL = NULL, LSL = NULL, distribution = c("normal", "beta"), sigma_type = c("known", "unknown"), theta_type = c("known", "unknown"), sigma = NULL, theta = NULL)optVarPlan(PRQ, CRQ, alpha = 0.05, beta = 0.10, USL = NULL, LSL = NULL, distribution = c("normal", "beta"), sigma_type = c("known", "unknown"), theta_type = c("known", "unknown"), sigma = NULL, theta = NULL)
PRQ |
Producer Risk Quality (must be within valid range for the chosen distribution). |
CRQ |
Consumer Risk Quality (must be greater than PRQ and within valid range). |
alpha |
Producer's risk (numeric between 0 and 1). |
beta |
Consumer's risk (numeric between 0 and 1). |
USL |
Upper Specification Limit (numeric). Only one of |
LSL |
Lower Specification Limit (numeric). Only one of |
distribution |
Measurement distribution: |
sigma_type |
Indicates whether sigma (population standard deviation) is |
theta_type |
Indicates whether theta (population precision parameter for beta) is |
sigma |
Known standard deviation (used for normal distribution). Required if |
theta |
Precision (dispersion) parameter for the beta distribution.
If unknown, it can be estimated from historical data using functions such as |
The function generates variable acceptance sampling plans based on specified producer and consumer risks and either a normal or beta distribution model.
The specification limit must be defined via either USL (upper specification limit) or LSL (lower specification limit), depending on whether the one-sided quality criterion concerns the upper or lower tail. Only one limit should be provided.
For the "normal" model, the plan can be computed assuming the standard deviation
(sigma) is either known or estimated from data. Optimization for unknown sigma
is performed using the derivative-free Nelder-Mead method (Nelder and Mead, 1965) via
optim in base R.
For the "beta" model, the dispersion (precision) parameter theta determines
how concentrated the distribution is around the mean. Users must either:
provide a known value for theta, typically obtained from prior process studies or historical data; or
estimate it from sample data using a fitting function such as betaff in the VGAM package.
Optimization for Beta plans is performed using optim with the "L-BFGS-B" method
(Byrd et al., 1995) to handle bounds on sample size and acceptance numbers.
This approach ensures stable and efficient plan calculation while relying solely on base R functionality.
A VarPlan object containing:
distribution |
Distribution used ("normal" or "beta"). |
sample_size |
Final sample size after rounding up to the next integer, for practical application. |
k |
Acceptability constant. |
n |
Unrounded sample size. |
Ha Truong
* ISO 3951-1:2013 - Sampling procedures for inspection by variables.
* Wilrich, PT. (2004). Single Sampling Plans for Inspection by Variables under a Variance Component Situation. In: Lenz, HJ., Wilrich, PT. (eds) Frontiers in Statistical Quality Control 7. Physica, Heidelberg.
* K. Govindaraju and R. Kissling (2015). Sampling plans for Beta-distributed compositional fractions.
* J. A. Nelder and R. Mead. A simplex method for function minimization. The Computer Journal, 7(4): 308–313, 1965. DOI 10.1093/comjnl/7.4.308.
* R. H. Byrd, P. Lu, J. Nocedal and C. Zhu. A limited memory algorithm for bound constrained optimization. SIAM Journal on Scientific Computing, 16(5): 1190–1208, 1995. DOI 10.1137/0916069.
# Example for normal distribution plan norm_plan <- optVarPlan( PRQ = 0.025, # Acceptable quality level (% nonconforming) CRQ = 0.1, # Rejectable quality level (% nonconforming) alpha = 0.05, # Producer's risk beta = 0.1, # Consumer's risk distribution = "normal", USL = 10 ) summary(norm_plan) # Example for beta distribution plan beta_plan <- optVarPlan( PRQ = 0.025, # Target quality level (% nonconforming) CRQ = 0.1, # Minimum quality level (% nonconforming) alpha = 0.05, # Producer's risk beta = 0.1, # Consumer's risk distribution = "beta", theta = 44000000, # Beta distribution parameter LSL = 0.00001 ) summary(beta_plan)# Example for normal distribution plan norm_plan <- optVarPlan( PRQ = 0.025, # Acceptable quality level (% nonconforming) CRQ = 0.1, # Rejectable quality level (% nonconforming) alpha = 0.05, # Producer's risk beta = 0.1, # Consumer's risk distribution = "normal", USL = 10 ) summary(norm_plan) # Example for beta distribution plan beta_plan <- optVarPlan( PRQ = 0.025, # Target quality level (% nonconforming) CRQ = 0.1, # Minimum quality level (% nonconforming) alpha = 0.05, # Producer's risk beta = 0.1, # Consumer's risk distribution = "beta", theta = 44000000, # Beta distribution parameter LSL = 0.00001 ) summary(beta_plan)
Plots the Operating Characteristic (OC) curve for an attribute sampling plan object of class AttrPlan.
## S3 method for class 'AttrPlan' plot(x, pd = NULL, ...)## S3 method for class 'AttrPlan' plot(x, pd = NULL, ...)
x |
An object of class |
pd |
Optional vector of proportions of nonconforming items. If |
... |
Additional graphical parameters passed to |
This method computes and visualizes the probability of acceptance (P(accept)) as a function of the proportion of nonconforming items in the population, based on the attribute sampling plan.
The plot also includes reference lines at the plan's producer and consumer quality levels (PRQ, CRQ) and their corresponding acceptance probabilities.
A plot showing the OC curve for the given attribute sampling plan.
Ha Truong
# Create attribute plan plan <- optAttrPlan(PRQ = 0.01, CRQ = 0.1) # Plot OC curve plot(plan) # With custom pd plot(plan, pd = seq(0, 0.15, by = 0.001))# Create attribute plan plan <- optAttrPlan(PRQ = 0.01, CRQ = 0.1) # Plot OC curve plot(plan) # With custom pd plot(plan, pd = seq(0, 0.15, by = 0.001))
Plots the Operating Characteristic (OC) curve from an object of class "OCdata", either by proportion nonconforming or process mean levels.
## S3 method for class 'OCdata' plot(x, by = c("pd", "mean"), ...)## S3 method for class 'OCdata' plot(x, by = c("pd", "mean"), ...)
x |
An object of class |
by |
A character string indicating the type of OC curve to plot. Options are:
|
... |
Additional graphical parameters passed to the |
This method visualizes the OC curve based on the content of the "OCdata" object.
By default, the curve is plotted against the proportion of nonconforming items (@pd). If by = "mean" is specified and the plan includes valid mean-level estimates (@process_means), the curve is plotted against mean levels.
If by = "mean" is requested but no mean estimates are available (e.g., for attribute plans), a message will be shown and no plot will be drawn.
A plot showing the OC curve for the given attribute/variable sampling plan.
Ha Truong
OCdata, optAttrPlan, optVarPlan
# Attribute plan plan_attr <- optAttrPlan(PRQ = 0.01, CRQ = 0.05) oc_attr <- OCdata(plan_attr) plot(oc_attr) # OC curve by pd (default) plot(oc_attr, by = "mean") # Will show message if not available # Variable plan plan_var <- optVarPlan(PRQ = 0.025, CRQ = 0.1, USL = 0.1, distribution = "normal", sigma=0.01) oc_var <- OCdata(plan_var) plot(oc_var) # OC curve by pd plot(oc_var, by = "mean") # OC curve by mean levels# Attribute plan plan_attr <- optAttrPlan(PRQ = 0.01, CRQ = 0.05) oc_attr <- OCdata(plan_attr) plot(oc_attr) # OC curve by pd (default) plot(oc_attr, by = "mean") # Will show message if not available # Variable plan plan_var <- optVarPlan(PRQ = 0.025, CRQ = 0.1, USL = 0.1, distribution = "normal", sigma=0.01) oc_var <- OCdata(plan_var) plot(oc_var) # OC curve by pd plot(oc_var, by = "mean") # OC curve by mean levels
Plots the Operating Characteristic (OC) curve for an object of class VarPlan. Supports plotting against either the proportion of nonconforming items or the corresponding process mean levels, depending on availability.
## S3 method for class 'VarPlan' plot(x, pd = NULL, by = c("pd", "mean"), ...)## S3 method for class 'VarPlan' plot(x, pd = NULL, by = c("pd", "mean"), ...)
x |
An object of class |
pd |
Optional numeric vector of proportions of nonconforming items to evaluate. If |
by |
Character string indicating which x-axis to use for plotting. Either |
... |
Additional graphical parameters passed to |
This plotting method visualizes the probability of acceptance (P(accept)) against the desired metric, based on the parameters of a variable sampling plan.
If by = "pd", the x-axis represents the proportion of nonconforming items. If by = "mean" and the plan defines limit_type and spec_limit, the function estimates corresponding process means using muEst and plots the OC curve by those mean values.
Reference lines for the Producer's Risk Quality (PRQ) and Consumer's Risk Quality (CRQ), along with their respective acceptance probabilities, are shown when plotting by proportion.
A plot showing the OC curve for the given variable sampling plan, either by nonconforming proportion or mean level.
Ha Truong
optVarPlan, accProb, muEst, OCdata, plot.OCdata
# Variable sampling plan with specification limits plan <- optVarPlan( PRQ = 0.025, CRQ = 0.1, alpha = 0.05, beta = 0.1, distribution = "normal", USL = 3, sigma = 0.1 ) # Plot by proportion nonconforming plot(plan, by = "pd") # Plot by estimated mean level (requires spec_limit and limit_type) plot(plan, by = "mean") # Custom pd vector plot(plan, pd = seq(0.01, 0.15, by = 0.001))# Variable sampling plan with specification limits plan <- optVarPlan( PRQ = 0.025, CRQ = 0.1, alpha = 0.05, beta = 0.1, distribution = "normal", USL = 3, sigma = 0.1 ) # Plot by proportion nonconforming plot(plan, by = "pd") # Plot by estimated mean level (requires spec_limit and limit_type) plot(plan, by = "mean") # Custom pd vector plot(plan, pd = seq(0.01, 0.15, by = 0.001))
Detailed summaries for attribute acceptance plans.
## S3 method for class 'AttrPlan' summary(object, ...)## S3 method for class 'AttrPlan' summary(object, ...)
object |
Plan object to summarize |
... |
Additional parameters (ignored) |
No return value. This function is called for its side effect of printing a formatted summary of the attribute sampling plan to the console.
Ha Truong
attr_plan <- optAttrPlan(PRQ = 0.01, CRQ = 0.1) summary(attr_plan)attr_plan <- optAttrPlan(PRQ = 0.01, CRQ = 0.1) summary(attr_plan)
Detailed summaries for Variables Acceptance Sampling plans.
## S3 method for class 'VarPlan' summary(object, ...)## S3 method for class 'VarPlan' summary(object, ...)
object |
Plan object to summarize |
... |
Additional parameters (ignored) |
No return value. This function is called for its side effect of printing a formatted summary of the variable sampling plan to the console.
Ha Truong
var_plan <- optVarPlan( PRQ = 0.025, # Acceptable quality level (% nonconforming) CRQ = 0.1, # Rejectable quality level (% nonconforming) alpha = 0.05, # Producer's risk beta = 0.1, # Consumer's risk distribution = "normal" ) summary(var_plan)var_plan <- optVarPlan( PRQ = 0.025, # Acceptable quality level (% nonconforming) CRQ = 0.1, # Rejectable quality level (% nonconforming) alpha = 0.05, # Producer's risk beta = 0.1, # Consumer's risk distribution = "normal" ) summary(var_plan)