The AccSamplingDesign package provides tools to create and evaluate acceptance sampling plans for both attribute and variable quality data. The focus is on controlling producer’s and consumer’s risk specifications while minimizing required sample sizes.
The package supports:
Install from CRAN:
Or from GitHub:
# Create an attribute plan with binomial assumption
plan_attr <- optPlan(
PRQ = 0.01, # Acceptable quality level (1%)
CRQ = 0.05, # Rejectable quality level (5%)
alpha = 0.02, # Producer's risk
beta = 0.15, # Consumer's risk
distribution = "binomial"
)
# Summary of the plan
summary(plan_attr)
#> Attributes Acceptance Sampling Plan:
#> Distribution: binomial
#> Sample Size (n): 144
#> Acceptance Number (c): 4
#> Producer's Risk (PR = 0.01534843 ) at PRQ = 0.01
#> Consumer's Risk (CR = 0.1487162 ) at CRQ = 0.05
# Probability of accepting 3% defective
accProb(plan_attr, 0.03)
#> [1] 0.5656415
# Plot the OC curve
plot(plan_attr)# Create a variable plan assuming known sigma
plan_var <- optPlan(
PRQ = 0.025,
CRQ = 0.1,
alpha = 0.05,
beta = 0.10,
distribution = "normal",
sigma_type = "known"
)
# Summary
summary(plan_var)
#> Variables Acceptance Sampling Plan
#> Distribution: normal
#> Sample Size (n, rounded up): 19 [raw n = 18.60721 ]
#> Acceptability Constant (k): 1.579
#> Population Standard Deviation: known
#> Producer's Risk (PR = 0.05 ) at PRQ = 0.025
#> Consumer's Risk (CR = 0.1 ) at CRQ = 0.1
# Plot OC curve
plot(plan_var)# Create a variable plan assuming known sigma
plan_var2 <- optPlan(
PRQ = 0.025,
CRQ = 0.1,
alpha = 0.05,
beta = 0.10,
distribution = "normal",
sigma_type = "unknown"
)
# Summary
summary(plan_var2)
#> Variables Acceptance Sampling Plan
#> Distribution: normal
#> Sample Size (n, rounded up): 43 [raw n = 42.67339 ]
#> Acceptability Constant (k): 1.586
#> Population Standard Deviation: unknown
#> Producer's Risk (PR = 0.05 ) at PRQ = 0.025
#> Consumer's Risk (CR = 0.1 ) at CRQ = 0.1# Create a variable plan using Beta distribution
plan_beta <- optPlan(
PRQ = 0.05,
CRQ = 0.2,
alpha = 0.05,
beta = 0.10,
distribution = "beta",
theta = 44000000,
theta_type = "known",
LSL = 0.00001 # Lower Specification Limit
)
# Summary
summary(plan_beta)
#> Variables Acceptance Sampling Plan
#> Distribution: beta
#> Sample Size (n, rounded up): 14 [raw n = 13.05195 ]
#> Acceptability Constant (k): 1.188
#> Population Precision Parameter (theta): known
#> Producer's Risk (PR = 0.05412522 ) at PRQ = 0.05
#> Consumer's Risk (CR = 0.1025498 ) at CRQ = 0.2
#> Lower Specification Limit (LSL): 1e-05
# Plot OC curve
plot(plan_beta)# Create a variable plan using Beta distribution
plan_beta2 <- optPlan(
PRQ = 0.05,
CRQ = 0.2,
alpha = 0.05,
beta = 0.10,
distribution = "beta",
theta = 44000000,
theta_type = "unknown",
LSL = 0.00001
)
# Summary
summary(plan_beta2)
#> Variables Acceptance Sampling Plan
#> Distribution: beta
#> Sample Size (n, rounded up): 31 [raw n = 30.79007 ]
#> Acceptability Constant (k): 1.188
#> Population Precision Parameter (theta): unknown
#> Producer's Risk (PR = 0.04808494 ) at PRQ = 0.05
#> Consumer's Risk (CR = 0.09474857 ) at CRQ = 0.2
#> Lower Specification Limit (LSL): 1e-05When designing a variables acceptance sampling plan using
optPlan() or optVarPlan(),
the returned object includes two related quantities for the sample
size:
sample_size — for practical
application, the final plan uses the smallest integer greater than or
equal to the theoretical value (ceiling(n)).n — the raw (non-rounded) computed
sample size based on the optimization model.Example:
For Beta-distributed quality characteristics, the precision parameter θ reflects the concentration of the distribution around the mean. If θ is unknown, it can be estimated from historical process data.
A practical approach is to use the VGAM package, which
provides the betaff function for fitting a Beta
distribution and obtaining θ:
# Example data
y <- c(0.75, 0.68, 0.72, 0.70, 0.76)
# Fit Beta model
fit <- vglm(y ~ 1, betaff, data = data.frame(y = y))
# Extract estimated parameters
coef(fit, matrix = TRUE)
#> logitlink(mu) loglink(phi)
#> (Intercept) 0.9544037 5.410654The output provides estimates of the mean (μ) and the precision
parameter (θ). Use the estimated θ directly in optPlan(),
e.g.:
theta_est <- exp(coef(fit, matrix = TRUE)[1, "loglink(phi)"])
theta_est
#> [1] 223.7778
optPlan(PRQ = 0.05, CRQ = 0.20, alpha = 0.05, beta = 0.10,
USL = 0.8, distribution = "beta", theta_type = "unknown",
theta = theta_est)
#> VarPlan object:
#> Distribution: beta
#> Theta type: unknown
#> Sample size (n): 31
#> Acceptability constant (k): 1.179908
#>
#> NOTE: summary(plan) for detail report,
#> plot(plan) for quick OC visualization,
#> OCdata(plan) to extract data for evaluation and custom plots.The AccSamplingDesign package determines optimal sample sizes and acceptance criteria for variable sampling plans via numerical optimization.
Normal Plans (σ unknown): Optimization is
performed using the derivative-free method of Nelder and Mead (1965) via
the optim() function in R. This method is robust for the
non-linear objective functions that arise when σ is unknown.
Beta Plans: Optimization is performed using the
optim() function in R with the "L-BFGS-B"
method (Byrd et al., 1995), which efficiently handles bound constraints
on sample size and acceptance numbers.
This approach ensures stable and efficient plan calculations while relying solely on base R functionality, avoiding additional package dependencies.
# Define range of defect rates
pd <- seq(0, 0.15, by = 0.001)
# Generate OC data from optimal plan
oc_opt <- OCdata(plan = plan_attr, pd = pd)
# Compare with manual plans
mplan1 <- manualPlan(n = plan_attr$n, c = plan_attr$c - 1, distribution = "binomial")
oc_alt1 <- OCdata(plan = mplan1, pd = pd)
# Plot comparison
plot(pd, oc_opt$paccept, type = "l", col = "blue", lwd = 2,
xlab = "Proportion Defective", ylab = "Probability of Acceptance",
main = "OC Curves Comparison for Attributes Sampling Plan")
lines(pd, oc_alt1$paccept, col = "red", lwd = 2, lty = 2)
legend("topright", legend = c("Optimal Plan", "Manual Plan c - 1"),
col = c("blue", "red"), lty = c(1, 2), lwd = 2)This vignette provides a quick start for using the AccSamplingDesign package. For a full discussion of the statistical foundations, models, and optimization methods used, please refer to the foundation sources such as:
Schilling, E.G., & Neubauer, D.V. (2017). Acceptance Sampling in Quality Control (3rd ed.). CRC Press.
Wilrich, P.T. (2004). Single Sampling Plans for Inspection by Variables under a Variance Component Situation. In Frontiers in Statistical Quality Control 7.
Govindaraju, K., & Kissling, R. (2015). Sampling plans for Beta-distributed compositional fractions. Quality Engineering, 27(1), 1–13.
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.