What does Survival Analysis for Livestream Retention conclude, in numbers, about “From Retention to Hazard: the Nelson-Aalen Estimator and the Entry Spike”?

Answer: Chapter 2 locates the entry spike with the Nelson-Aalen estimator, the hazard in the first two seconds being 133.3 times that of settled viewers, and shows how casually marked spikes produce false reports.

Scope of the numbers: Its rooms, audiences, hazard parameters, hook effects and run sheets are illustrative; all calculations are generated by its programs; the book is not individual business advice. Marked boxes separate published evidence, runnable Python calculations (18 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: 133.3

Nelson-Aalen H(t): 5s 0.38610s 0.53230s 0.66360s 0.716600s 1.350
hazard after 600 s in the room: 0.00074 per s
bin (s)exitsviewer-shazard/sratio
0-256056780.09863133.3
2-432947000.0700094.6
4-620141160.0488366.0
6-1018273220.0248633.6
10-20164163120.0100513.6
20-3048153630.003124.2
30-6079442230.001792.4
60-120108829120.001301.8
120-3002942082470.001411.9
300-6002622571100.001021.4
peak bin 0-2 s is 133 times the settled hazard

Key formula

\[\hat H(t) = \sum_{t_i \le t} \frac{d_i}{n_i}.\]
Show the full program
# Chapter 2. p21: Nelson-Aalen cumulative hazard and binned swipe hazard.
# Same illustrative room R as p11 (same seed). On the viewer's own clock
# (seconds since entry) it computes the Nelson-Aalen estimate
# H(t) = sum over exit times of d/n, the hazard per bin as exits divided
# by viewer-seconds at risk, and the ratio of each bin to the hazard
# measured after the first ten minutes in the room.
import math
import random

T_END = 3600
SWITCH = [180, 900, 1260, 1980, 2700]   # 环节切换秒数(示意)
SPIKE_LEN, B_SW = 30, 0.012
LAM0 = 1.0 / 600.0
A_OPEN, TAU = 0.12, 6.0
SHAPE = 2.0


def prog_hazard(horizon):
    h = [LAM0] * horizon
    for s in SWITCH:
        for t in range(s, s + SPIKE_LEN):
            h[t] = LAM0 + B_SW
    return h


def open_int(u):
    return A_OPEN * TAU * (math.exp(-u / TAU) - math.exp(-(u + 1) / TAU))


def simulate(seed, horizon=T_END):
    rng = random.Random()
    rng.seed(seed)
    ent = [rng.randrange(0, 60) for _ in range(400)]
    ent += [rng.randrange(0, 3300) for _ in range(2600)]
    ent.sort()
    ph = prog_hazard(horizon)
    rows = []
    for e in ent:
        z = rng.gammavariate(SHAPE, 1.0 / SHAPE)
        need = rng.expovariate(1.0)
        cum, t = 0.0, e
        while t < horizon:
            cum += z * (ph[t] + open_int(t - e))   # step
            t += 1
            if cum >= need:
                break
        if cum >= need:
            rows.append((e, t - e, 1))
        else:
            rows.append((e, horizon - e, 0))
    return rows


def nelson_aalen(rows):
    # 每个退出秒数 t:H += d / n(n = 停留至少 t 秒的人数)
    dur = sorted((d, ev) for _, d, ev in rows)
    n, i, incs, out = len(dur), 0, [], []
    while i < len(dur):
        t = dur[i][0]
        d = 0
        j = i
        while j < len(dur) and dur[j][0] == t:
            d += dur[j][1]   # step
            j += 1
        if d:
            incs.append(d / n)
            out.append((t, math.fsum(incs)))
        n -= j - i   # step
        i = j
    return out


def binned(rows, lo, hi):
    # 区间 [lo, hi) 内:退出数 / 在场人秒
    ev = len([1 for _, d, e in rows if e and lo < d <= hi])
    expo = math.fsum(min(d, hi) - lo for _, d, _ in rows if d > lo)
    return ev, expo, ev / expo


rows = simulate(20261113)
na = nelson_aalen(rows)
late = binned(rows, 600, 3600)[2]


def h_at(t):
    v = 0.0
    for tt, hh in na:
        if tt > t:
            break
        v = hh
    return v


print("Nelson-Aalen H(t): " + "  ".join(
    "%ds %.3f" % (t, h_at(t)) for t in (5, 10, 30, 60, 600)))
print("hazard after 600 s in the room: %.5f per s" % late)
print(" bin (s)      exits  viewer-s   hazard/s  ratio")
for lo, hi in ((0, 2), (2, 4), (4, 6), (6, 10), (10, 20), (20, 30),
               (30, 60), (60, 120), (120, 300), (300, 600)):
    ev, ex, h = binned(rows, lo, hi)
    print("%4d-%-5d %8d %9.0f %10.5f %6.1f"
          % (lo, hi, ev, ex, h, h / late))
first = binned(rows, 0, 2)[2]
print("peak bin 0-2 s is %.0f times the settled hazard" % (first / late))

Single source and citation

Fan, Y. (2026). Kaplan-Meier Retention Curves for Livestream Rooms: Locating Swipe-Away Hazard Spikes and Timing the Insertion of Hooks (Version 1.0.0), Chapter 2: From Retention to Hazard: the Nelson-Aalen Estimator and the Entry Spike. 5D Library. DOI pending

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

BibTeX
@book{fan2026277,
  author    = {Fan, Yafu},
  title     = {Kaplan-Meier Retention Curves for Livestream Rooms: Locating Swipe-Away Hazard Spikes and Timing the Insertion of Hooks},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

Other chapter answers in this book