영업 부서의 담당자가 무역 박람회에서 나눠줄 공급업체로부터 수건을 구입합니다. 영업 담당자는 전체 수건 로트가 승인되거나 거부되도록 샘플링 계획을 구현하려고 합니다. 분석 개수는 결함 수가 됩니다. 각 수건에는 실이 당겨지거나 색상이 변하는 등 하나 이상의 결함이 있을 수 있습니다. 영업 담당자와 공급업체는 다음 요구 사항에 동의합니다.
  • 샘플링 계획의 AQL은 0.01입니다. 분석의 알파는 0.05입니다. 수건 100장당 결함이 1개인 로트를 많이 받아들일 확률은 최소 95%입니다.
  • RQL은 0.06입니다. 분석의 베타는 0.10입니다. 수건 100장당 6개의 결함이 있는 로트를 거부할 확률은 최소 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과 R을 통합하는 R 패키지입니다. 예제에서는 이 모듈의 함수가 R 결과를 Minitab으로 보냅니다. Minitab 패키지를 설치하는 방법에 대한 자세한 내용은 2단계를 참조하십시오. R 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