What does Hidden Markov Models for Customer Decision Stages conclude, in numbers, about “Closing the Loop: a Weekly Stage Review, the Customer Stage Decoder and Pre-Registered Tests”?
Answer: Chapter 8 gives the weekly review, the Customer Stage Decoder and pre-registered tests: test one needs 372 visits with a self-reported stage, test two 5301 chats per arm. Marked boxes separate published evidence, runnable Python calculations (18 programs), classical sources and the author's hypotheses.
Scope of the numbers: 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: 372, 5301
| test 1: forward filter vs last click, ready-or-not | |
| discordant: filter-only right 0.1295, last-only right 0.0655 | |
| difference 0.0640; McNemar needs 372 surveyed visits | |
| at survey response 0.10 | 3720 consented visits invited |
| at survey response 0.20 | 1860 consented visits invited |
| test 2: opt-out or complaint share 0.040 vs 0.030 | |
| chats per arm | 5301, total 10602 |
| at 300 non-price chats a week | 35.3 weeks |
| at 1000 non-price chats a week | 10.6 weeks |
Show the full program
# Chapter 8. p82: sample sizes for the pre-registered tests.
# Test 1 (paired, McNemar): on consented visits whose stage is later
# self-reported in a one-question survey, does the forward filter call
# ready-or-not right more often than the last-click rule? The discordant
# shares are taken from a fixed-seed simulation of the p11 HMM (4,000
# visits, as in p11). Test 2 (two proportions): does the quote rule of
# p61 lower the share of chats that end in an opt-out or complaint,
# from an assumed 0.040 under "always quote" to 0.030? alpha 0.05 two-
# sided, power 0.80. All inputs illustrative.
import math
import random
from statistics import NormalDist
PI = [0.70, 0.20, 0.08, 0.02]
A = [[0.70, 0.22, 0.06, 0.02],
[0.08, 0.64, 0.23, 0.05],
[0.02, 0.10, 0.66, 0.22],
[0.01, 0.03, 0.16, 0.80]]
B = [[0.45, 0.30, 0.08, 0.07, 0.06, 0.04],
[0.15, 0.35, 0.25, 0.12, 0.08, 0.05],
[0.08, 0.22, 0.15, 0.30, 0.17, 0.08],
[0.05, 0.12, 0.08, 0.15, 0.30, 0.30]]
K = 4
Z = NormalDist()
ZA, ZB = Z.inv_cdf(0.975), Z.inv_cdf(0.80)
def draw(rng, probs):
u, acc = rng.random(), 0.0
for k, p in enumerate(probs):
acc += p # step
if u < acc:
return k
return len(probs) - 1
rng = random.Random(20261113)
n = 4000
f_only = l_only = 0
for _ in range(n):
t_len = rng.randint(6, 14)
s = [draw(rng, PI)]
for _ in range(t_len - 1):
s.append(draw(rng, A[s[-1]]))
o = [draw(rng, B[k]) for k in s]
f = [PI[k] * B[k][o[0]] for k in range(K)]
m = PI[:]
for x in o[1:]:
z = math.fsum(f)
f = [math.fsum(f[i] / z * A[i][j] for i in range(K)) * B[j][x]
for j in range(K)]
m = [math.fsum(m[i] * A[i][j] for i in range(K)) for j in range(K)]
fr = max(range(K), key=lambda k: f[k]) >= 2
lr = max(range(K), key=lambda k: m[k] * B[k][o[-1]]) >= 2
truth = s[-1] >= 2
f_only += 1 if (fr == truth and lr != truth) else 0 # step
l_only += 1 if (lr == truth and fr != truth) else 0 # step
p10, p01 = f_only / n, l_only / n
pd, d = p10 + p01, p10 - p01
n_mc = (ZA * math.sqrt(pd) + ZB * math.sqrt(pd - d * d)) ** 2 / (d * d)
print("test 1: forward filter vs last click, ready-or-not")
print(" discordant: filter-only right %.4f, last-only right %.4f"
% (p10, p01))
print(" difference %.4f; McNemar needs %d surveyed visits"
% (d, math.ceil(n_mc)))
for resp in (0.10, 0.20):
print(" at survey response %.2f: %d consented visits invited"
% (resp, math.ceil(math.ceil(n_mc) / resp)))
p1, p2 = 0.040, 0.030
pbar = (p1 + p2) / 2
n2 = (ZA * math.sqrt(2 * pbar * (1 - pbar))
+ ZB * math.sqrt(p1 * (1 - p1) + p2 * (1 - p2))) ** 2 / (p1 - p2) ** 2
print("test 2: opt-out or complaint share %.3f vs %.3f" % (p1, p2))
print(" chats per arm: %d, total %d" % (math.ceil(n2), 2 * math.ceil(n2)))
for per_week in (300, 1000):
print(" at %d non-price chats a week: %.1f weeks"
% (per_week, 2 * math.ceil(n2) / per_week))Single source and citation
Fan, Y. (2026). Hidden Markov Models and Viterbi Decoding: Inferring a Customer's Hidden Decision Stage from Click Sequences and Timing the Offer (Version 1.0.0), Chapter 8: Closing the Loop: a Weekly Stage Review, the Customer Stage Decoder and Pre-Registered Tests. 5D Library. DOI pending
DOI pending · monograph page goes live after publication · 5DL-B-300 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026300,
author = {Fan, Yafu},
title = {Hidden Markov Models and Viterbi Decoding: Inferring a Customer's Hidden Decision Stage from Click Sequences and Timing the Offer},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}Other chapter answers in this book
- Chapter 1 · The Last-Click Illusion: Whole Sequences against a Single Page
- Chapter 2 · The Viterbi Trellis: Dynamic Programming in Logarithms, Backtracking and Underflow
- Chapter 3 · Forward and Backward: Posterior Marginals, the Best Path and "Wait Two More Clicks"
- Chapter 4 · Baum–Welch: Estimating Parameters from Unlabelled Clickstreams
- Chapter 5 · Identifiability and Label Switching: What Clickstreams Cannot Say
- Chapter 6 · Timing the Offer: the Inquiry as Evidence, a Cost Threshold and Calibration
- Chapter 7 · Classical Sources East and West: Markov's Letter Chain in Onegin and the Chuai Chapter of the Guiguzi