销售部门的代表从供应商处购买毛巾,以便在贸易展览上赠送。销售代表希望实施抽样计划,以便接受或拒绝整批毛巾。分析计数将是缺陷的数量。每条毛巾可能有多个缺陷,例如拉线或颜色变化。销售代表和供应商就以下要求达成一致:
  • 抽样计划的 AQL 为 0.01。分析的 alpha 为 0.05。每 100 条毛巾接受 1 个缺陷的批次的概率至少为 95%。
  • RQL 为 0.06。分析的贝塔系数为 0.10。每 6 条毛巾有 100 个缺陷的批次拒绝的概率至少为 90%。

当测量类型为缺陷数,质量水平的单位为每单位缺陷数时,该脚本近似于 Minitab Statistical Software 中按属性抽样验收 中的值。

示例 R 脚本演示了集成的以下功能:
  • 从 Minitab Statistical Software 中的列中读取值。
  • 将值表发送到 Minitab 输出窗格。
  • 在 Minitab 输出窗格中显示来自 R 标准误差的警告和消息。
使用以下文件执行本节中的步骤:
文件 说明
acceptance_sampling.R 一种脚本, R 用于从 Minitab 工作表中的列中获取规格,并显示 OC 曲线的值表。

以下 .ZIP 文件提供了本指南中引用的所有文件:r_guide_files.zip

预修课程

  • 该脚本依靠列名来给出分析规范: AQL, alpha, RQL, beta.

  • 以下示例中的 R 脚本需要以下 R 包:
    mtbr
    集成 Minitab 和 RR 包。在该示例中,此模块中的函数将 R 结果发送到 Minitab。有关如何安装 Minitab 软件 R 包的信息,请转至 步骤 2: 安装 mtbr

运行示例的步骤

  1. 确保已安装所需模块:mtbr
  2. R 脚本文件 acceptance_sampling.R 保存到 Minitab 默认文件位置。 有关 Minitab 在何处查找 R 脚本文件的更多信息,请转到 Minitab 的 R 文件的默认文件夹
  3. 打开样本数据集R_抽样验收.MWX
  4. 在 Minitab 命令行窗格中,输入 RSCR "acceptance_sampling.R"
  5. 选择 运行

acceptance_sampling.R

# Load necessary library
#Original code by Valentina Tillman
library(mtbr)

# Define Parameters
AQL <- mtb_get_column("AQL")  # Acceptable Quality Level
alpha <- mtb_get_column("alpha")  # Producer's risk
RQL <- mtb_get_column("RQL")  # Rejectable Quality Level
beta <- mtb_get_column("beta")  # Consumer's risk

# ---- Validate inputs ----

# Validate AQL and RQL
if (is.null(AQL) || length(AQL) != 1 || is.na(AQL)) {
  warning("Define the AQL with a value in the first row of a column with the title AQL.")
}
if (is.null(RQL) || length(RQL) != 1 || is.na(RQL)) {
  warning("Define the RQL with a value in the first row of a column with the title RQL.")
}

# Validate alpha
if (is.null(alpha) || length(alpha) != 1 || is.na(alpha)) {
  alpha <- 0.05
  message("Missing or multiple values for alpha. The analysis uses 0.05. To specify alpha, enter a value in the first row of a column with the title alpha.")
}

# Validate beta
if (is.null(beta) || length(beta) != 1 || is.na(beta)) {
  beta <- 0.10
  message("Missing or multiple values for beta. The analysis uses 0.10. To specify beta, enter a value in the first row of a column with the title beta.")
}

#Simple comparison of AQL and RQL
if (AQL >= RQL) {
  stop("Specify an RQL that is greater than the AQL.")
}

# ---- Calculations ----
# Use algorithm to find n,c for the Poisson distribution
found <- FALSE
for (n in 10:5000) {
  lamA <- n*AQL
  lamR <- n*RQL
  for (c in 0:n) {
    p_accept_AQL <- ppois(c, lamA)
    p_accept_RQL <- ppois(c, lamR)
    if (p_accept_AQL >= 1 - alpha && p_accept_RQL <= beta) {
      found <- TRUE
      break
    }
  }
  if (found) break
}

if (found != TRUE) { 
  mtb_add_message ("No solution found. Results are for the largest values of n and c in the search.")
  }

# Generate OC curve values for number of defects per unit
p_vals <- seq(0.003, 0.117, by = 0.006)
lambda_vals <- p_vals * n
OC_vals <- ppois(c, lambda_vals)

# ---- Outputs ----
#Display analysis inputs
show_AQL <- sprintf("AQL: %s", sub("\\.?0+$", "", formatC(AQL, format = "f", digits = 6)))
mtb_add_message(show_AQL)
show_RQL <- sprintf("RQL: %s", sub("\\.?0+$", "", formatC(RQL, format = "f", digits = 6)))
mtb_add_message(show_RQL)
show_alpha <- sprintf("alpha: %s", sub("\\.?0+$", "", formatC(alpha, format = "f", digits = 6)))
mtb_add_message(show_alpha)
show_beta <- sprintf("beta: %s", sub("\\.?0+$", "", formatC(beta, format = "f", digits = 6)))
mtb_add_message(show_beta)

#Display calculated solutions
show_sample_size <- sprintf("Sample size: %d", n)
mtb_add_message(show_sample_size)
show_defects <- sprintf("Acceptance number: %d", c)
mtb_add_message(show_defects)

# OC Curve Table
oc_table <- data.frame("Lot_Defects_per_Unit" = p_vals, "Probability_of_Acceptance" = OC_vals)
head(oc_table, 10)

mytitle <- "OC Table" 
myheaders <- names(oc_table)
mtb_add_table(columns = oc_table, headers = myheaders, title = mytitle)

结果

R Script

这些结果来自外部软件。
AQL: 0.01
RQL: 0.06
alpha: 0.05
beta: 0.1
Sample size: 112
Acceptance number: 3

OC Table

Lot_Defects_per_UnitProbability_of_Acceptance
0.0030.999593
0.0090.980517
0.0150.909779
0.0210.788694
0.0270.641855
0.0330.494988
0.0390.365054
0.0450.259456
0.0510.178812
0.0570.120085
0.0630.078892
0.0690.050862
0.0750.032260
0.0810.020172
0.0870.012457
0.0930.007607
0.0990.004600
0.1050.002757
0.1110.001639
0.1170.000968