What does Three-City Teams: Handoffs and Acceptance conclude, in numbers, about “When the Defect Rate Is Unknown or Drifts: Bayesian Updating, Sample Size and the Inspection Interval”?

Answer: When the defect rate is unknown, what a sample buys is information, and the sample size worth paying for has an interior optimum: 42 items with the illustrative parameters, on a curve that is flat between 20 and 60 items. Accumulated data create inertia, letting an old good record suppress a new warning, so old data must retire or a single-week alarm line must be set. When the defect rate can drift, the inspection interval has an interior optimum too, 2.32 days with the illustrative parameters, and it moves with the square root of the drift rate. "The more often the better" fails in time just as it fails in space.

Scope of the numbers: Its schedules, lunch breaks, cost coefficients, exchange-rate volatilities and price levels are illustrative, and all calculations are generated by its programs. It is general management guidance, not individual, legal or tax advice; labour, tax and work-pass matters in the three cities must be confirmed by licensed local advisers.

中文版

Data table

The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python onlyprinted values that match the answer: 20, 42, 60

n expected h per lot
0100.00
5100.00
1089.63
2083.56
3083.52
6082.95
12089.18
best n42, 81.98 h; inspect-all 100.0 h; ship-all 125.0 h
week n d posterior mean P(p > 0.04) action
142 0 0.0161 0.083 ship rest
242 1 0.0192 0.079 ship rest
342 0 0.0137 0.019 ship rest
442 0 0.0106 0.004 ship rest
542 6 0.0348 0.301 ship rest
642 4 0.0441 0.599 inspect rest
Show the full program
# Chapter 5. p51: Bayesian defect rate and the sample size worth paying for.
# Costs as in p42: k1 = 0.5 h per inspection, k2 = 12.5 h per escape, so
# the breakeven rate is 0.04; lots of N = 200. Prior on a new stream's
# defect rate p: Beta(1, 19), mean 0.05 (illustrative). Sampling n items
# and finding d defectives gives Beta(1 + d, 19 + n - d). After the
# sample the coordinator inspects the rest if the posterior mean exceeds
# 0.04 and ships it otherwise. Part one: expected cost per lot by n
# (preposterior analysis, beta-binomial predictive). Part two: a stream
# updated week by week with samples of the best n.
import math

K1, K2, N, A, B = 0.5, 12.5, 200, 1.0, 19.0
BREAK = K1 / K2


def lbeta(a, b):
    return math.lgamma(a) + math.lgamma(b) - math.lgamma(a + b)


def pred(n, d, a, b):
    return math.comb(n, d) * math.exp(lbeta(a + d, b + n - d) - lbeta(a, b))


def exp_cost(n, a=A, b=B):
    terms = [n * K1]
    for d in range(n + 1):
        post = (a + d) / (a + b + n)
        rest = (N - n) * min(K1, post * K2)
        terms.append(pred(n, d, a, b) * rest)
    return math.fsum(terms)


def tail(a, b, x0, steps=4000):
    # P(p > x0) under Beta(a, b), Simpson's rule on [x0, 1]
    h = (1 - x0) / steps
    f = [math.exp((a - 1) * math.log(x0 + i * h)
                  + (b - 1) * math.log(max(1e-300, 1 - x0 - i * h))
                  - lbeta(a, b)) for i in range(steps + 1)]
    w = [1 if i in (0, steps) else 4 if i % 2 else 2
         for i in range(steps + 1)]
    return h / 3 * math.fsum(wi * fi for wi, fi in zip(w, f))


print("n     expected h per lot")
for n in (0, 5, 10, 20, 30, 60, 120):
    print("%-5d %10.2f" % (n, exp_cost(n)))
best = min(range(0, N), key=lambda n: (exp_cost(n), n))
print("best n = %d, %.2f h; inspect-all %.1f h; ship-all %.1f h" % (
    best, exp_cost(best), N * K1, N * A / (A + B) * K2))
a, b = A, B
print("week  n  d  posterior mean  P(p > 0.04)  action")
for wk, d in enumerate((0, 1, 0, 0, 6, 4), 1):
    a, b = a + d, b + best - d
    m = a / (a + b)
    act = "inspect rest" if m > BREAK else "ship rest"
    print("%4d %3d %2d %12.4f %12.3f   %s" % (wk, best, d, m,
                                           tail(a, b, BREAK), act))

Single source and citation

Fan, Y. (2026). Distributed Multi-City Team Coordination, Asynchronous Deliverable Verification and Regional Talent Allocation across KL, Taipei and HCMC (Version 1.0.0), Chapter 5: When the Defect Rate Is Unknown or Drifts: Bayesian Updating, Sample Size and the Inspection Interval. 5D Library. DOI pending

DOI pending · monograph page goes live after publication · 5DL-B-340 · v1.0.0 · CC-BY-NC-ND-4.0

BibTeX
@book{fan2026340,
  author    = {Fan, Yafu},
  title     = {Distributed Multi-City Team Coordination, Asynchronous Deliverable Verification and Regional Talent Allocation across KL, Taipei and HCMC},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

Other chapter answers in this book