What does CUSUM Alarms conclude, in numbers, about “One Line of Recursion: the CUSUM Is a Running Log-Likelihood Ratio”?

Answer: To keep the same false-alarm budget with two sides, the limit must rise from 4.096 to 4.775, since now two sums can each raise a false alarm. The price is paid in detection speed. For a shift of half a standard deviation the average run length grows from 27.7 days to 35.3 days, 7.6 days more; for a quarter of a standard deviation it grows from 81.9 days to 121.6 days, 39.7 days more. The larger the shift, the smaller the price: at one standard deviation it is only 1.4 days.

Scope of the numbers: Parameters are illustrative; all calculations are generated by the book's programs; the book is general business analysis, not individualised business advice, and Chapter 8 is an offline model that reads no server. Marked boxes separate published evidence, runnable Python calculations (23 programs), classical sources and the author's hypotheses.

中文版

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: 1.4, 121.6, 27.7, 35.3, 39.7, 4.096

one-sided h = 4.096, ARL0 = 370.0
two-sided h = 4.775, ARL0 = 370.0
shiftone-sidedtwo-sidedextra days
0.2581.9121.639.7
0.5027.735.37.6
1.008.69.91.4
2.003.43.90.5
Show the full program
# Chapter 2. p23: watching both directions costs delay in the one that
# matters.
# Model: an upper and a lower CUSUM run side by side (k = 0.5). With
# ARL+ and ARL- from the Brook and Evans chain, the two-sided ARL is
# taken from 1 / ARL = 1 / ARL+ + 1 / ARL- (exact enough when k is not
# small). The two-sided h is found so that ARL0 = 370, and compared with
# the one-sided h of p12 for upward shifts (illustrative).
import math


def cdf(x):
    return 0.5 * math.erfc(-x / math.sqrt(2.0))


def upper(x):
    return 0.5 * math.erfc(x / math.sqrt(2.0))


def solve(a, b):
    # Gaussian elimination with partial pivoting; back substitution
    # adds its terms with math.fsum
    n = len(b)
    m = [list(row) + [b[i]] for i, row in enumerate(a)]
    for p in range(n):
        q = max(range(p, n), key=lambda r: abs(m[r][p]))
        m[p], m[q] = m[q], m[p]
        piv = m[p]
        for r in range(p + 1, n):
            f = m[r][p] / piv[p]
            if f != 0.0:
                m[r] = m[r][:p] + [x - f * y for x, y in
                                   zip(m[r][p:], piv[p:])]
    x = [0.0] * n
    for i in range(n - 1, -1, -1):
        s = math.fsum(m[i][j] * x[j] for j in range(i + 1, n))
        x[i] = (m[i][n] - s) / m[i][i]
    return x


def arl(k, h, delta, m=80):
    w = 2.0 * h / (2 * m - 1)
    a = []
    for i in range(m):
        c = i * w - k + delta
        row = [-cdf(w / 2.0 - c)]
        for j in range(1, m):
            row.append(cdf(j * w - w / 2.0 - c)
                       - cdf(j * w + w / 2.0 - c))
        row[i] = row[i] + 1.0
        a.append(row)
    return solve(a, [1.0] * m)[0]


def limit_for(arl0):
    lo, hi = 0.0, 10.0
    for _ in range(200):
        mid = 0.5 * (lo + hi)
        if upper(mid) > 1.0 / arl0:
            lo = mid
        else:
            hi = mid
    return 0.5 * (lo + hi)


def h_for(k, target, m=80):
    lo, hi = 0.5, 12.0
    for _ in range(40):
        mid = 0.5 * (lo + hi)
        if arl(k, mid, 0.0, m) < target:
            lo = mid
        else:
            hi = mid
    return 0.5 * (lo + hi)


def two_sided(k, h, d):
    up, down = arl(k, h, d), arl(k, h, -d)
    return 1.0 / (1.0 / up + 1.0 / down)


if __name__ == "__main__":
    k = 0.5
    h1 = h_for(k, 370.0)
    h2 = h_for(k, 740.0)
    print("one-sided h = {:.3f}, ARL0 = {:.1f}".format(h1, arl(k, h1, 0.0)))
    print("two-sided h = {:.3f}, ARL0 = {:.1f}".format(
        h2, two_sided(k, h2, 0.0)))
    print(" shift  one-sided  two-sided  extra days")
    for d in (0.25, 0.5, 1.0, 2.0):
        a1 = arl(k, h1, d)
        a2 = two_sided(k, h2, d)
        print(" {:5.2f}  {:9.1f}  {:9.1f}  {:10.1f}".format(
            d, a1, a2, a2 - a1))

Single source and citation

Fan, Y. (2026). CUSUM Control Charts and Average Run Length: the Fastest Alarm within a False-Alarm Budget for Latency Drift and Silent Conversion Drops (Version 1.0.0), Chapter 2: One Line of Recursion: the CUSUM Is a Running Log-Likelihood Ratio. 5D Library. DOI pending

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

BibTeX
@book{fan2026305,
  author    = {Fan, Yafu},
  title     = {CUSUM Control Charts and Average Run Length: the Fastest Alarm within a False-Alarm Budget for Latency Drift and Silent Conversion Drops},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

Other chapter answers in this book