This vignette illustrates how an auditor can use jfa
to evaluate their sample outcomes with the Bayes factor using summary statistics alone. An example application in the context of quality control is described below.
Two-stage sampling plans are required if an initial sample does not provide enough assurance to accept (or reject) a population definitively. In the field of quality control, ISO 28596 ‘Sampling procedures for inspection by attributes — Two-stage sampling plans for auditing and for inspection under prior information’ provides two-stage sampling plans by attributes for inspection for a proportion of nonconforming items in a target population of discrete units. For example, this standard applies for inspections of a proportion of nonconforming items in a lot of product items, or inspections of the proportion of nonconforming test characteristics of a product subject to an acceptance test.
The idea behind the standard two-stage sampling plan is simple. In the first stage, after drawing \(n_1\) items and observing \(k_1\) nonconforming items, a confidence interval for the proportion of nonconforming items is calculated. The decision in the first stage proceeds according to one of the three following scenarios:
In the second stage, a number \(k_2\) of nonconforming items is observed in a sample of size \(n_2\). A new confidence interval for the proportion of nonconforming items is calculated based on the total number \(k_1 + k_2\) of nonconforming items. The decision in the second stage proceeds according to one of the two following scenarios:
The auditor is inspecting a lot of products and wants to make a statement with 90% confidence against a tolerance value of 5%. They formulate the hypothesis of intolerable deviations as \(H_0:\theta \geq 0.05\) and the hypothesis of tolerable deviations as \(H_1: \theta < 0.05\).
<- 0.90 # 90% confidence
confidence <- 0.05 # 5% tolerance tolerance
In the first stage, the auditor inspects \(n_1 = 32\) items and observes \(k_1 = 2\) nonconforming items. The shortest two-sided confidence interval (Göb & Lurz, 2012) for the proportion of nonconforming items is [0.0167; 0.1866]. This confidence interval contains the tolerance value and therefore no decision can be made in the first stage. The auditor therefore continues to the second stage.
:::CI.binom.shortest(size = 32, x = 2, level = confidence)$bounds
ISO28596# x estimate lower upper
# [1,] 2 0.0625 0.01674365 0.1866428
In the second stage, the auditor inspects an additional \(n_2 = 50\) items and observes \(k_2 = 0\) nonconforming items. After observing these data, the shortest two-sided confidence interval for the proportion of nonconforming items (using \(n = n_1 + n_2\) and \(k = k_1 + k_2\)) is [0.0065; 0.0734]. At this point, the confidence interval still contains the tolerance value but the auditor determines that the portion of the confidence interval that lies below the tolerance value is larger than the portion above the tolerance value. Therefore, they accept the lot.
:::CI.binom.shortest(size = 32 + 50, x = 2 + 0, level = confidence)$bounds
ISO28596# x estimate lower upper
# [1,] 2 0.02439024 0.006504196 0.07341118
The jfa
package can be used to calculate Bayes factors for the hypothesis of tolerable deviations \(H_1\) in the lot versus the hypothesis of intolerable deviations \(H_0\) in the lot. The Bayes factor can provide insight into the weight of evidence in favor of acceptance of the lot versus the evidence in favor of rejection of the lot. Especially in the situation where the confidence interval contains the tolerance value the Bayes factor can provide an easy interpretation of the evidence in favor of acceptance versus rejection.
\[BF_{10} = \underbrace{\frac{p(\text{data} | H_1)}{p(\text{data} | H_0)}}_{\text{Relative evidence}} \]
To calculate the Bayes factor the auditor must first specify the prior distribution for the proportion of nonconforming items in the lot. An appropriate prior distribution can be one that assigns equal probability to the event of acceptance and the event of rejection (Derks et al., 2021). This prior distribution can be constructed using the auditPrior()
function in combination with the argument method = 'median'
(see also the vignette Prior distributions).
<- auditPrior(confidence, tolerance, method = 'median')
prior plot(prior)
Using the evaluation()
function the auditor can calculate the Bayes factor in favor of acceptance of the lot versus rejection of the lot. In this case, the Bayes factor in favor of acceptance (\(BF_{-+}\)) is 0.665 and represents only anecdotal evidence in favor of rejection (see also the vignette Testing misstatement).
evaluation(confidence, tolerance, nSumstats = 32, kSumstats = 2, prior = prior)
## # ------------------------------------------------------------
## # jfa Evaluation Summary (Bayesian)
## # ------------------------------------------------------------
## # Input:
## #
## # Confidence: 90%
## # Materiality: 5%
## # Minium precision: Not specified
## # Sample size: 32
## # Sample errors: 2
## # Sum of taints: 2
## # Method: binomial
## # Prior distribution: beta(a = 1, ß = 13.513)
## # ------------------------------------------------------------
## # Output:
## #
## # Posterior distribution: beta(a = 3, ß = 43.513)
## # Most likely error: 4.3%
## # Upper bound: 11.274%
## # Precision: 6.974%
## # Bayes factor-+: 0.665
## # Conclusion: Do not approve population
## # ------------------------------------------------------------
The Bayes factor in favor of acceptance after the second sample of items is 6.24 which represents moderate evidence in favor of acceptance.
evaluation(confidence, tolerance, nSumstats = 32 + 50, kSumstats = 2 + 0, prior = prior)
## # ------------------------------------------------------------
## # jfa Evaluation Summary (Bayesian)
## # ------------------------------------------------------------
## # Input:
## #
## # Confidence: 90%
## # Materiality: 5%
## # Minium precision: Not specified
## # Sample size: 82
## # Sample errors: 2
## # Sum of taints: 2
## # Method: binomial
## # Prior distribution: beta(a = 1, ß = 13.513)
## # ------------------------------------------------------------
## # Output:
## #
## # Posterior distribution: beta(a = 3, ß = 93.513)
## # Most likely error: 2.072%
## # Upper bound: 5.476%
## # Precision: 3.404%
## # Bayes factor-+: 6.241
## # Conclusion: Do not approve population
## # ------------------------------------------------------------
In the Bayesian framework, the auditor can continue to accumulate and monitor evidence one item at the time. This means that the auditor can continue sampling until a certain threshold of evidence is reached.
Derks, K., de Swart, J., van Batenburg, P., Wagenmakers, E.-J., and Wetzels, R. (2021). Priors in a Bayesian audit: How integration of existing information into the prior distribution can improve audit transparency and efficiency. In press.
Göb R. & Lurz, K. (2014). Shortest two-sided confidence intervals for a probability under prior information. Metrika: International Journal for Theoretical and Applied Statistics, 77 (3), 389-413.