Title: | Acceptance Sampling Plans Design |
Version: | 0.0.6 |
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. |
License: | GPL-3 |
Encoding: | UTF-8 |
Imports: | stats, methods |
Suggests: | knitr, rmarkdown |
VignetteBuilder: | knitr |
URL: | https://github.com/vietha/AccSamplingDesign |
BugReports: | https://github.com/vietha/AccSamplingDesign/issues |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-07-18 20:15:49 UTC; hatruong |
Author: | Ha Truong [aut, cre, cph], Victor Miranda [ths, rev], Roger Kissling [ths, rev] |
Maintainer: | Ha Truong <truongvietha87@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-07-18 20:30:02 UTC |
Generic function for OC Curve Generation
Description
Generic function to compute Operating Characteristic (OC) curve data from an acceptance sampling plan.
Usage
OCdata(plan, pd = NULL)
Arguments
plan |
An object of class |
pd |
Vector of quality levels (proportions of nonconforming items). |
Details
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.
Value
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
Author(s)
Ha Truong
See Also
Acceptance Probability
Description
Calculate the probability of acceptance for a given quality level.
Usage
accProb(plan, p)
Arguments
plan |
Acceptance plan object ( |
p |
True quality level (proportion of nonconforming). |
Value
Numeric probability between 0 and 1.
Author(s)
Ha Truong
Examples
# 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)
Create manual acceptance sampling (AS) plan from User Inputs
Description
Constructs an AttrPlan
or VarPlan
object from the given parameters.
Usage
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"))
Arguments
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 |
Details
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.
Value
An object of class "AttrPlan"
or VarPlan
.
Author(s)
Ha Truong
See Also
Examples
# 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)
Estimate Mean \mu
Based on Specification Limits and Probability
Description
Computes the estimated mean \mu
for a given level of quality and specification limit under either a normal or beta distribution.
Usage
muEst(p, USL = NULL, LSL = NULL,
sigma = NULL, theta = NULL,
dist = c("normal", "beta"))
Arguments
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 |
Details
The function estimates the mean \mu
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 bytheta
.
Exactly one of USL
or LSL
must be provided to define whether the probability refers to the upper or lower tail.
Value
Returns the estimated mean \mu
as a numeric value.
Author(s)
Ha Truong
Examples
# 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")
Attribute Acceptance Sampling Plan
Description
Designs binomial-based acceptance sampling plans using producer/consumer risk criteria.
Usage
optAttrPlan(PRQ, CRQ, alpha = 0.05, beta = 0.10,
distribution = c("binomial", "poisson"))
Arguments
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 |
Value
AttrPlan object containing:
n |
Sample size |
c |
Acceptance number |
PRQ |
Input PRQ value |
CRQ |
Input CRQ value |
distribution |
Selected distribution |
Author(s)
Ha Truong
References
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
Examples
plan <- optAttrPlan(PRQ = 0.01, CRQ = 0.1, alpha = 0.05, beta = 0.1,
distribution = "binomial")
Optimal Acceptance Sampling Plan
Description
Design optimal variable acceptance sampling plans based on specified parameters. Supports different distributions (binomial, normal, beta) and accommodates known or unknown standard deviation and process parameters.
Usage
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)
Arguments
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 |
Known process parameter (e.g., mean), if applicable. |
Details
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.
Value
Returns a list or data frame with optimal sample size(s) and critical value(s) based on the specified parameters and distribution.
Author(s)
Ha Truong
Examples
# 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)
Variable Acceptance Sampling Plan
Description
Creates variable sampling plans for normal or beta distributed measurements.
Usage
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)
Arguments
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 |
Dispersion parameter (used for beta distribution). Required if |
Details
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.
The plan design accounts for known or unknown standard deviation in the normal case, and known or unknown dispersion parameter (theta
) in the beta case. Measurement error, if any, can be incorporated via the measurement_error
argument.
Value
A VarPlan
object containing:
distribution |
Distribution used ("normal" or "beta"). |
sample_size |
Final sample size after rounding (integer). |
k |
Acceptability constant. |
n |
Unrounded sample size. |
Author(s)
Ha Truong
References
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. doi:10.1007/978-3-7908-2674-6_4
K. Govindaraju and R. Kissling (2015). Sampling plans for Beta-distributed compositional fractions.
Examples
# 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)
Plot the OC Curve for Attribute Sampling Plans
Description
Plots the Operating Characteristic (OC) curve for an attribute sampling plan object of class AttrPlan
.
Usage
## S3 method for class 'AttrPlan'
plot(x, pd = NULL, ...)
Arguments
x |
An object of class |
pd |
Optional vector of proportions of nonconforming items. If |
... |
Additional graphical parameters passed to |
Details
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.
Value
A plot showing the OC curve for the given attribute sampling plan.
Author(s)
Ha Truong
See Also
Examples
# 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))
Plot Method for OCdata Objects
Description
Plots the Operating Characteristic (OC) curve from an object of class "OCdata"
, either by proportion nonconforming or process mean levels.
Usage
## S3 method for class 'OCdata'
plot(x, by = c("pd", "mean"), ...)
Arguments
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 |
Details
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.
Value
A plot showing the OC curve for the given attribute/variable sampling plan.
Author(s)
Ha Truong
See Also
OCdata
, optAttrPlan
, optVarPlan
Examples
# 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
Plot the OC Curve for Variable Sampling Plans
Description
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.
Usage
## S3 method for class 'VarPlan'
plot(x, pd = NULL, by = c("pd", "mean"), ...)
Arguments
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 |
Details
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.
Value
A plot showing the OC curve for the given variable sampling plan, either by nonconforming proportion or mean level.
Author(s)
Ha Truong
See Also
optVarPlan
, accProb
, muEst
, OCdata
, plot.OCdata
Examples
# 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))
Summarize Attribute Acceptance Plan
Description
Detailed summaries for attribute acceptance plans.
Usage
## S3 method for class 'AttrPlan'
summary(object, ...)
Arguments
object |
Plan object to summarize |
... |
Additional parameters (ignored) |
Value
No return value. This function is called for its side effect of printing a formatted summary of the attribute sampling plan to the console.
Author(s)
Ha Truong
Examples
attr_plan <- optAttrPlan(PRQ = 0.01, CRQ = 0.1)
summary(attr_plan)
Summarize Variable Acceptance Plan
Description
Detailed summaries for variable acceptance plans.
Usage
## S3 method for class 'VarPlan'
summary(object, ...)
Arguments
object |
Plan object to summarize |
... |
Additional parameters (ignored) |
Value
No return value. This function is called for its side effect of printing a formatted summary of the variable sampling plan to the console.
Author(s)
Ha Truong
Examples
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)