关于「睡眠追踪器能知道什么,以及让你睡不着的那个分数」,《睡眠的算术》给出的定量结论是什么?

结论:第六章说明完美设备与人工判读者的 kappa 也只有 0.815,设备只认出 0.571 的深睡眠时段,分数的逐晚变化(相关 0.640)比分数本身(0.708)更嘈杂,并把「正睡症」写成一个明确标为假说的反馈环。

数据口径:本书不是医疗建议,不给任何剂量,不推荐任何产品;持续失眠的一线治疗是失眠的认知行为疗法。 书中以标注框区分已发表的证据、可运行的 Python 计算(16 段程序)、原典与作者的假说;除注明的文献外,书中数据都是合成的。

English version

对照数据表

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

                                         agreement   Cohen's kappa
   scorer A vs scorer B                   0.788       0.671
   scorer A vs truth                      0.881       0.815
   device vs truth                        0.694       0.510
   device vs scorer A                     0.637       0.420
   perfect device (= truth) vs scorer A   0.881       0.815
Minutes per night by stage (mean over 200 nights)
   last column: share of epochs of this stage the device gets right
   stage     truth   device   device - truth   right
   wake       47.2    43.5      -3.8           0.543
   light     253.1   274.6     +21.5           0.779
   deep       75.2    69.1      -6.2           0.571
   REM       104.4    92.9     -11.5           0.644
Night-to-night correlation of device deep minutes with true deep
minutes: 0.953
Reading: a validation study compares the device with a scorer, not with
the truth, so even a perfect device cannot score above the scorers' own
agreement with the truth. The device's nightly averages can be close while
it misses almost half of the deep-sleep epochs: errors in both directions
cancel. Caution: here the device errs independently epoch by epoch, so its
errors average out over a night. Real errors are correlated within a night
(posture,
heart-rate patterns), which p12 allows for; the 0.953 is an upper bound.
查看完整验算程序
# Chapter 6. How well can a wrist or ring device stage sleep, and how would we
# know? True stages come from the p05 chain (N1 and N2 merged as "light"). Two
# human scorers and a device each read the true stage with their own confusion
# probabilities (illustrative values: the scorers agree with each other about
# 80 % of epochs, of the order reported for expert polysomnography scoring;
# the device is a plausible consumer tracker). We compute accuracy and Cohen's
# kappa against the truth and against one scorer, which is all a validation
# study can do.
import math
import random

W, L, D, R = range(4)
NAMES = ("wake", "light", "deep", "REM")

SCORER = [[0.90, 0.08, 0.00, 0.02],
          [0.03, 0.89, 0.04, 0.04],
          [0.00, 0.20, 0.80, 0.00],
          [0.02, 0.07, 0.00, 0.91]]
DEVICE = [[0.55, 0.35, 0.02, 0.08],
          [0.05, 0.78, 0.09, 0.08],
          [0.01, 0.40, 0.57, 0.02],
          [0.04, 0.30, 0.02, 0.64]]

def truth_night(rng):
    st, since, seq = 0, 0, []
    for e in range(960):
        t = e / 120.0
        s = math.exp(-t / 2.5)
        u = rng.random()
        if st == 0:
            st = 1 if u < 0.045 else 0
        elif st == 1:
            st = 2 if u < 0.10 else (0 if u < 0.12 else 1)
        elif st == 2:
            p3 = 0.05 * s
            pr = 0.0 if since < 100 else 0.03 * (0.5 + t / 8)
            st = (
                3
                if u < p3
                else (
                    4
                    if u < p3 + pr
                    else (
                        1
                        if u < p3 + pr + 0.006
                        else 0 if u < p3 + pr + 0.009 else 2
                    )
                )
            )
        elif st == 3:
            po = 0.012 + 0.05 * (1 - s)
            st = 2 if u < po else 0 if u < po + 0.001 else 3
        else:
            pe = 1.0 / (20 + 50 * t / 8)
            st = 2 if u < pe * 0.8 else 0 if u < pe else 4
        since = 0 if st == 4 else since + 1
        seq.append({0: W, 1: L, 2: L, 3: D, 4: R}[st])
    return seq

def read(seq, conf, rng):
    out = []
    for s in seq:
        u, acc = rng.random(), 0.0
        for j, p in enumerate(conf[s]):
            acc += p
            if u < acc:
                out.append(j)
                break
        else:
            out.append(3)
    return out

def kappa(a, b):
    n = len(a)
    po = sum(x == y for x, y in zip(a, b)) / n
    pe = sum((a.count(k) / n) * (b.count(k) / n) for k in range(4))
    return po, (po - pe) / (1 - pe)

if __name__ == "__main__":
    rng = random.Random(57011)
    T, A, B, Dv = [], [], [], []
    deep_t, deep_d = [], []
    for _ in range(200):
        t = truth_night(rng)
        dv = read(t, DEVICE, rng)
        T += t
        A += read(t, SCORER, rng)
        B += read(t, SCORER, rng)
        Dv += dv
        deep_t.append(t.count(D) / 2)
        deep_d.append(dv.count(D) / 2)
    print(
        "                                         agreement   Cohen's kappa"
    )
    for name, x, y in (
        ("scorer A vs scorer B", A, B),
        ("scorer A vs truth", A, T),
        ("device vs truth", Dv, T),
        ("device vs scorer A", Dv, A),
        ("perfect device (= truth) vs scorer A", T, A),
    ):
        po, k = kappa(x, y)
        print("   {:<38}{:6.3f}      {:6.3f}".format(name, po, k))
    print("\nMinutes per night by stage (mean over 200 nights)")
    print(
        "   last column: share of epochs of this stage the device gets right"
    )
    print("   stage     truth   device   device - truth   right")
    for k in range(4):
        tt, dd = T.count(k) / 400, Dv.count(k) / 400
        hit = sum(1 for x, y in zip(T, Dv) if x == k and y == k) / T.count(k)
        print(
            "   {:<7}  {:6.1f}  {:6.1f}    {:+6.1f}           {:.3f}".format(
                NAMES[k], tt, dd, dd - tt, hit
            )
        )
    mt, md = sum(deep_t) / 200, sum(deep_d) / 200
    cov = sum((a - mt) * (b - md) for a, b in zip(deep_t, deep_d))
    r = cov / math.sqrt(
        sum((a - mt) ** 2 for a in deep_t)
        * sum((b - md) ** 2 for b in deep_d)
    )
    print(
        "\nNight-to-night correlation of device deep minutes with true deep"
    )
    print("minutes: {:.3f}".format(r))
    print("\nReading: a validation study compares the"
          " device with a scorer, not with")
    print("the truth, so even a perfect device cannot"
          " score above the scorers' own")
    print("agreement with the truth. The device's nightly"
          " averages can be close while")
    print("it misses almost half of the deep-sleep"
          " epochs: errors in both directions")
    print("cancel. Caution: here the device errs"
          " independently epoch by epoch, so its")
    print("errors average out over a night. Real errors"
          " are correlated within a night")
    print("(posture,")
    print(
        "heart-rate patterns), which p12 allows for; the {:.3f} is an upper"
        " bound.".format(r)
    )

唯一数据源与引用

范雅福(Fan, Y.). (2026). 《双过程睡眠架构、慢波胶质淋巴清除与体温节律相位控制》第 6 章「睡眠追踪器能知道什么,以及让你睡不着的那个分数」(版本 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090162

DOI: 10.5281/zenodo.24090162 · 阅读本章所在专著 · 5DL-B-057 · v1.0.0 · CC-BY-NC-ND-4.0

BibTeX
@book{fan2026057,
  author    = {Fan, Yafu},
  title     = {Two-Process Sleep Architecture, Slow-Wave Glymphatic Clearance and Thermoregulatory Phase Control},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  doi       = {10.5281/zenodo.24090162},
  url       = {https://doi.org/10.5281/zenodo.24090162}
}

本书其他章节结论