关于「门店实验的设计:不偷看、不早停、先配对、按模拟定天数」,《门店小实验的重抽样推断》给出的定量结论是什么?

结论:第六章讲不偷看、不早停与配对:每天看一次使误报率升到 0.1714,按周配对的精确符号翻转检验 p 为 0.0234,不配对则为 0.8008。

数据口径:书中参数为示意;全部计算由书中程序生成;本书属于非个人化经营建议。 书中以标注框区分已发表的证据、可运行的 Python 计算(20 段程序)、原典与作者的假说。

English version

对照数据表

下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 0.0234, 0.8008

weekly differences: 55 30 -12 70 25 48 5 38
mean difference 32.38
paired sign-flip exact: 6 of 256p = 0.0234
unpaired exact: 10306 of 12870p = 0.8008
paired t = 3.432p = 0.0109
sd between weeks 251.0sd of differences 26.7
查看完整验算程序
# Chapter 6. p63: pair what varies, then flip signs exactly.
# Model: two near-identical counters in one shop for 8 weeks; each
# week a coin decides which counter shows the new display. Weekly
# takings (yuan, illustrative) swing with holidays, so weeks differ far
# more than counters do. Paired analysis: under H0 the sign of each
# weekly difference is a fair coin, so all 2^8 = 256 sign patterns are
# equally likely (exact sign-flip test). Unpaired analysis of the same
# 16 numbers enumerates all C(16, 8) = 12870 splits. Paired t (p11).
import itertools
import math

def betacf(a, b, x):
    tiny = 1e-300
    qab, qap, qam = a + b, a + 1.0, a - 1.0
    c = 1.0
    d = 1.0 - qab * x / qap
    d = 1.0 / (d if abs(d) > tiny else tiny)
    h = d
    for m in range(1, 300):
        m2 = 2 * m
        aa = m * (b - m) * x / ((qam + m2) * (a + m2))
        d = 1.0 + aa * d
        d = 1.0 / (d if abs(d) > tiny else tiny)
        c = 1.0 + aa / c
        c = c if abs(c) > tiny else tiny
        h *= d * c
        aa = -(a + m) * (qab + m) * x / ((a + m2) * (qap + m2))
        d = 1.0 + aa * d
        d = 1.0 / (d if abs(d) > tiny else tiny)
        c = 1.0 + aa / c
        c = c if abs(c) > tiny else tiny
        de = d * c
        h *= de
        if abs(de - 1.0) < 1e-15:
            break
    return h


def betai(a, b, x):
    if x <= 0.0:
        return 0.0
    if x >= 1.0:
        return 1.0
    lb = (math.lgamma(a + b) - math.lgamma(a) - math.lgamma(b)
          + a * math.log(x) + b * math.log(1.0 - x))
    bt = math.exp(lb)
    if x < (a + 1.0) / (a + b + 2.0):
        return bt * betacf(a, b, x) / a
    return 1.0 - bt * betacf(b, a, 1.0 - x) / b


def t_two_tail(t, v):
    return betai(v / 2.0, 0.5, v / (v + t * t))


def t_cdf(t, v):
    half = 0.5 * t_two_tail(t, v)
    return 1.0 - half if t > 0 else half


def t_crit(alpha, v):
    lo, hi = 0.0, 1000.0
    for _ in range(200):
        mid = 0.5 * (lo + hi)
        if t_two_tail(mid, v) > alpha:
            lo = mid
        else:
            hi = mid
    return 0.5 * (lo + hi)

OLD = [820, 1150, 900, 1480, 760, 1010, 1290, 880]
NEW = [875, 1180, 888, 1550, 785, 1058, 1295, 918]


if __name__ == "__main__":
    d = [b - a for a, b in zip(OLD, NEW)]
    n = len(d)
    obs = math.fsum(d)
    ge = 0
    for signs in itertools.product((1, -1), repeat=n):
        ge += abs(math.fsum(s * v for s, v in zip(signs, d))) >= abs(obs)
    print("weekly differences: {}".format(" ".join(str(v) for v in d)))
    print("mean difference {:.2f}".format(obs / n))
    print("paired sign-flip exact: {} of {}  p = {:.4f}".format(
        ge, 2 ** n, ge / 2 ** n))
    pool = OLD + NEW
    tot = math.fsum(pool)
    d0 = abs(math.fsum(NEW) - math.fsum(OLD))
    ge2 = cnt = 0
    for idx in itertools.combinations(range(16), 8):
        s = math.fsum(pool[i] for i in idx)
        cnt += 1
        ge2 += abs(2 * s - tot) >= d0 - 1e-9
    print("unpaired exact: {} of {}  p = {:.4f}".format(ge2, cnt, ge2 / cnt))
    m = obs / n
    sd = math.sqrt(math.fsum((v - m) ** 2 for v in d) / (n - 1))
    t = m / (sd / math.sqrt(n))
    print("paired t = {:.3f}  p = {:.4f}".format(t, t_two_tail(t, n - 1)))
    sdw = math.sqrt(math.fsum((v - math.fsum(OLD) / n) ** 2 for v in OLD)
                    / (n - 1))
    print("sd between weeks {:.1f}  sd of differences {:.1f}".format(sdw, sd))

唯一数据源与引用

范雅福(Fan, Y.). (2026). 《自助法与置换检验、小样本门店实验不靠正态假设的重抽样推断母典》第 6 章「门店实验的设计:不偷看、不早停、先配对、按模拟定天数」(版本 1.0.0). 5D Library. DOI 待发布

DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-308 · v1.0.0 · CC-BY-NC-ND-4.0

BibTeX
@book{fan2026308,
  author    = {Fan, Yafu},
  title     = {The Bootstrap and Permutation Tests: Resampling Inference for Small Shop Experiments without Normality Assumptions},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

本书其他章节结论