experiment-toolkit 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/.github/workflows/ci.yml +10 -0
  2. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/.gitignore +1 -0
  3. experiment_toolkit-0.3.0/CHANGELOG.md +150 -0
  4. experiment_toolkit-0.3.0/PKG-INFO +315 -0
  5. experiment_toolkit-0.3.0/README.md +265 -0
  6. experiment_toolkit-0.3.0/docs/bandit_eval.png +0 -0
  7. experiment_toolkit-0.3.0/docs/bandit_eval_results.md +103 -0
  8. experiment_toolkit-0.3.0/docs/canary_drift.png +0 -0
  9. experiment_toolkit-0.3.0/docs/canary_drift_results.md +40 -0
  10. experiment_toolkit-0.3.0/docs/judge_audit.png +0 -0
  11. experiment_toolkit-0.3.0/docs/judge_audit_results.md +84 -0
  12. experiment_toolkit-0.3.0/docs/judge_drift.png +0 -0
  13. experiment_toolkit-0.3.0/docs/judge_drift_results.md +71 -0
  14. experiment_toolkit-0.3.0/docs/llm_judge.png +0 -0
  15. experiment_toolkit-0.3.0/docs/llm_judge_results.md +91 -0
  16. experiment_toolkit-0.3.0/docs/offline_online.png +0 -0
  17. experiment_toolkit-0.3.0/docs/offline_online_results.md +58 -0
  18. experiment_toolkit-0.3.0/docs/ppi_covariates.png +0 -0
  19. experiment_toolkit-0.3.0/docs/ppi_covariates_results.md +89 -0
  20. experiment_toolkit-0.3.0/docs/silent_drift.png +0 -0
  21. experiment_toolkit-0.3.0/docs/silent_drift_results.md +80 -0
  22. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/pyproject.toml +3 -2
  23. experiment_toolkit-0.3.0/scripts/bandit_eval_sim.py +381 -0
  24. experiment_toolkit-0.3.0/scripts/canary_drift_sim.py +281 -0
  25. experiment_toolkit-0.3.0/scripts/judge_audit_mtbench.py +314 -0
  26. experiment_toolkit-0.3.0/scripts/judge_drift_sim.py +244 -0
  27. experiment_toolkit-0.3.0/scripts/llm_judge_sim.py +357 -0
  28. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/scripts/make_hero.py +7 -5
  29. experiment_toolkit-0.3.0/scripts/offline_online_sim.py +264 -0
  30. experiment_toolkit-0.3.0/scripts/ppi_covariates_sim.py +332 -0
  31. experiment_toolkit-0.3.0/scripts/silent_drift_sim.py +326 -0
  32. experiment_toolkit-0.3.0/src/experiment_toolkit/__init__.py +89 -0
  33. experiment_toolkit-0.3.0/src/experiment_toolkit/bandit_eval.py +332 -0
  34. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/src/experiment_toolkit/cs_did.py +32 -27
  35. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/src/experiment_toolkit/cuped.py +13 -0
  36. experiment_toolkit-0.3.0/src/experiment_toolkit/judge_audit.py +231 -0
  37. experiment_toolkit-0.3.0/src/experiment_toolkit/judge_drift.py +573 -0
  38. experiment_toolkit-0.3.0/src/experiment_toolkit/llm_judge.py +475 -0
  39. experiment_toolkit-0.3.0/src/experiment_toolkit/offline_eval.py +257 -0
  40. experiment_toolkit-0.3.0/src/experiment_toolkit/ppi_covariates.py +283 -0
  41. experiment_toolkit-0.3.0/src/experiment_toolkit/py.typed +0 -0
  42. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/src/experiment_toolkit/sample_size.py +8 -4
  43. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/src/experiment_toolkit/sensitivity.py +54 -30
  44. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/src/experiment_toolkit/sequential.py +25 -5
  45. experiment_toolkit-0.3.0/tests/test_bandit_eval.py +158 -0
  46. experiment_toolkit-0.3.0/tests/test_judge_audit.py +105 -0
  47. experiment_toolkit-0.3.0/tests/test_judge_drift.py +288 -0
  48. experiment_toolkit-0.3.0/tests/test_llm_judge.py +225 -0
  49. experiment_toolkit-0.3.0/tests/test_offline_eval.py +137 -0
  50. experiment_toolkit-0.3.0/tests/test_ppi_covariates.py +120 -0
  51. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/tests/test_toolkit.py +11 -9
  52. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/tests/test_v02_additions.py +91 -1
  53. experiment_toolkit-0.2.0/CHANGELOG.md +0 -44
  54. experiment_toolkit-0.2.0/PKG-INFO +0 -129
  55. experiment_toolkit-0.2.0/README.md +0 -82
  56. experiment_toolkit-0.2.0/src/experiment_toolkit/__init__.py +0 -41
  57. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/.github/workflows/publish.yml +0 -0
  58. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/CONTRIBUTING.md +0 -0
  59. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/LICENSE +0 -0
  60. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/docs/hero.png +0 -0
  61. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/src/experiment_toolkit/cli.py +0 -0
  62. {experiment_toolkit-0.2.0 → experiment_toolkit-0.3.0}/src/experiment_toolkit/ratio.py +0 -0
@@ -26,3 +26,13 @@ jobs:
26
26
  run: ruff check .
27
27
  - name: Test
28
28
  run: pytest
29
+ - name: Smoke-run evidence scripts
30
+ run: |
31
+ python scripts/llm_judge_sim.py --smoke
32
+ python scripts/offline_online_sim.py --smoke
33
+ python scripts/ppi_covariates_sim.py --smoke
34
+ python scripts/judge_drift_sim.py --smoke
35
+ python scripts/silent_drift_sim.py --smoke
36
+ python scripts/bandit_eval_sim.py --smoke
37
+ python scripts/canary_drift_sim.py --smoke
38
+ python scripts/judge_audit_mtbench.py --smoke
@@ -12,5 +12,6 @@ dist/
12
12
  .mypy_cache/
13
13
  .coverage
14
14
  .DS_Store
15
+ data/
15
16
  .idea/
16
17
  .vscode/
@@ -0,0 +1,150 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.3.0] - 2026-11-27
11
+
12
+ ### Added
13
+ - `judge_audit`: real-data audit of an LLM judge against expert human
14
+ judgments on MT-Bench (Zheng et al., 2023, CC BY 4.0), downloaded at runtime
15
+ from a pinned revision and checked against SHA-256 hashes. Lines up human
16
+ and GPT-4 verdicts item by item, estimates the judge's win-rate bias with a
17
+ question-level bootstrap, splits agreement by which model humans preferred,
18
+ and runs a known-answer resampling check of judge-only, human-only and
19
+ PPI++ readouts. New `data` extra (`pyarrow`) for reading the parquet files.
20
+ - `scripts/judge_audit_mtbench.py`: seeded, single-command audit that writes
21
+ `docs/judge_audit_results.md` and `docs/judge_audit.png`. CI smoke-runs it
22
+ on synthetic data with the real schema.
23
+ - `judge_drift`: canary-set drift monitor. `simulate_canary` re-judges a fixed
24
+ set of stored outputs daily under a `SilentDrift`, with a `repeatability`
25
+ setting for how often the judge repeats its verdict. `canary_alarm` is a
26
+ paired, Bonferroni-corrected monitor on those verdicts, and
27
+ `canary_detection_prob` / `canary_items_for_power` give closed-form
28
+ detection probability and canary size.
29
+ - `scripts/canary_drift_sim.py`: seeded, single-command simulation that writes
30
+ `docs/canary_drift_results.md` and `docs/canary_drift.png`. CI smoke-runs it.
31
+ - `judge_drift`: silent judge drift with no version flag. `SilentDrift` changes
32
+ the judge from an unknown day (step or linear ramp, per arm) or shifts true
33
+ quality with the judge unchanged. `analyze_silent` compares the judge-only
34
+ readout with PPI++ using launch-week or whole-test random labels, and
35
+ `first_alarm` is a windowed, Bonferroni-corrected drift monitor for judge
36
+ scores or for judge-human agreement split by the human label. Closed forms
37
+ are included for the judge-only mean, the large-sample bias of launch-week
38
+ labels, and the chance that one monitor check flags.
39
+ - `scripts/silent_drift_sim.py`: seeded, single-command simulation that writes
40
+ `docs/silent_drift_results.md` and `docs/silent_drift.png`. CI smoke-runs it.
41
+ - `bandit_eval`: measuring the lift of a creative that a bandit picked from
42
+ many generated variants. Off-policy estimators that use logged propensities
43
+ (`ope_lift` with IPS, SNIPS or doubly robust; `policy_terms`), the naive
44
+ dashboard comparison (`naive_lift`), a selection helper (`pick_winner`), a
45
+ minimal batched Thompson-sampling log generator with click-rate drift and an
46
+ optional evaluation slice whose outcomes the bandit never sees
47
+ (`simulate_bandit_log`), and a closed-form winner's-curse reference for a
48
+ fixed equal split (`expected_winner_bias_fixed`). Evaluation only; still no
49
+ bandit framework.
50
+ - `scripts/bandit_eval_sim.py`: seeded, single-command simulation that writes
51
+ `docs/bandit_eval_results.md` and `docs/bandit_eval.png`. CI smoke-runs it.
52
+ - `judge_drift`: a judge model upgraded mid-test. Simulates a switch to a new
53
+ judge (with per-arm error rates) partway through an A/B test, and compares
54
+ the pooled judge score, the pre-upgrade judge score, and PPI++ with labels
55
+ spread across the test, labels only before the upgrade, or labels
56
+ stratified by judge version. Closed forms are included for the naive means
57
+ and SEs and for the large-sample bias of front-loaded labels.
58
+ - `scripts/judge_drift_sim.py`: seeded, single-command simulation that writes
59
+ `docs/judge_drift_results.md` and `docs/judge_drift.png`. CI smoke-runs it.
60
+ - `ppi_covariates`: PPI++ with several control variates, combining the LLM
61
+ judge score with a pre-treatment covariate in the CUPED style. Includes
62
+ closed-form oracle variance `Var(Y)/n · (1 − R² · N/(N+n))`, label budgets
63
+ for a target power (`labels_for_power`), and a simulator. With an
64
+ uninformative covariate it reproduces `llm_judge`'s PPI++ exactly.
65
+ - `scripts/ppi_covariates_sim.py`: seeded, single-command simulation that
66
+ writes `docs/ppi_covariates_results.md` and `docs/ppi_covariates.png`.
67
+ CI smoke-runs it.
68
+ - `offline_eval`: offline LLM evals vs online A/B tests. Simulates segment
69
+ mix shift between the eval set and live traffic, judge error that differs
70
+ between baseline and candidate outputs, and online-only costs. It compares
71
+ the raw judge readout, a readout post-stratified to the traffic mix, and
72
+ PPI++ with human labels per segment against the online A/B result.
73
+ Closed-form expectations are included for every readout.
74
+ - `scripts/offline_online_sim.py`: seeded, single-command simulation that
75
+ writes `docs/offline_online_results.md` and `docs/offline_online.png`.
76
+ - `--smoke` mode for both evidence scripts. CI now runs both in smoke mode,
77
+ so a clean-install break in an evidence pipeline fails the build.
78
+ - `llm_judge`: A/B tests whose primary metric is scored by an LLM judge.
79
+ Simulates binary true quality and a judge with per-arm sensitivity /
80
+ specificity, which allows differential error between arms. Provides the naive
81
+ judge-only analysis (`naive_judge_diff`) and PPI / PPI++ correction
82
+ (`ppi_mean_diff`; Angelopoulos et al. 2023) that uses a small human-labeled
83
+ sample from each arm. Also adds closed-form helpers for the expected naive
84
+ bias, SEs, rejection rates and sample-size inflation.
85
+ - `scripts/llm_judge_sim.py`: seeded, single-command simulation that writes
86
+ `docs/llm_judge_results.md` and `docs/llm_judge.png`, with every simulated
87
+ number shown next to its closed-form value. Known-answer and Type-I tests
88
+ live in `tests/test_llm_judge.py`.
89
+
90
+ ### Changed
91
+ - **Breaking:** `msprt_cuped_pvalue` now requires `tau`. The old default, the
92
+ SD of the CUPED-adjusted outcome, made the mixing prior data-dependent and
93
+ broke the always-valid guarantee. Choose `tau` before the test, for example
94
+ from the minimum detectable effect.
95
+ - **Breaking:** `e_value(kind="or", rare=False)` now requires `p0`, the
96
+ baseline outcome risk in the unexposed group, instead of assuming
97
+ `p0 = 0.1`.
98
+ - `e_value` accepts a signed SMD, so a negative `d` is treated as protective
99
+ instead of being rejected.
100
+ - Ships a `py.typed` marker (PEP 561).
101
+
102
+ ### Fixed
103
+ - `e_value` handles protective effects and uses the CI bound closest to the
104
+ null (lower bound when RR > 1, upper bound when RR < 1).
105
+ - `cs_did`: bootstrap replicates stay aligned across (g, t) cells, which fixes
106
+ invalid event-study and overall standard errors. Panels whose cohort varies
107
+ within a unit are now rejected.
108
+ - `msprt_cuped_pvalue` validates equal arm lengths and `0 < n_per_arm <= min(len)`.
109
+ - `mde_for_n` validates `alpha` and `power`; CUPED requires `|rho| < 1` and
110
+ validates input shapes, lengths and finiteness.
111
+ - The Rosenbaum bounds docstring now says the Wilcoxon p-value is a normal
112
+ approximation, not the exact small-sample value.
113
+
114
+ ## [0.2.0] - 2026-04-19
115
+
116
+ ### Added
117
+ - `cs_did`: Callaway & Sant'Anna (2021) staggered difference-in-differences
118
+ with never-treated controls and a unit cluster bootstrap for inference.
119
+ Includes `simulate_staggered_panel` for teaching / tests. Robust to
120
+ treatment-effect heterogeneity across cohorts — unlike TWFE.
121
+ - `sensitivity`: E-value (VanderWeele & Ding 2017) for risk-ratio / odds-ratio
122
+ / standardised-mean-difference effects and Rosenbaum bounds for matched-pair
123
+ Wilcoxon signed-rank tests (`rosenbaum_wilcoxon_bounds`,
124
+ `rosenbaum_gamma_threshold`).
125
+ - `sequential`: `msprt_cuped_pvalue` composes CUPED variance reduction with
126
+ mSPRT to tighten always-valid peeks.
127
+ - `sample_size`: `rho` parameter added to `sample_size_for_mde` / `mde_for_n`
128
+ for CUPED-aware power planning. Zero-default keeps v0.1 behaviour.
129
+ New `cuped_sample_size_summary` reports side-by-side naive vs CUPED sample
130
+ sizes and percent savings.
131
+
132
+ ### Notes
133
+ - Pure-numpy / scipy; no new runtime dependencies.
134
+ - All v0.1.0 APIs remain backwards compatible.
135
+
136
+ ## [0.1.0] - 2026-04-19
137
+
138
+ ### Added
139
+ - `sample_size`: two-sample sample size / MDE / power calculations.
140
+ - `cuped`: variance reduction via pre-experiment covariate (Deng et al. 2013).
141
+ - `ratio`: delta-method variance for ratio metrics (Deng et al. 2018).
142
+ - `sequential`: always-valid mSPRT sequential test (Johari et al. 2017).
143
+ - `cli`: command-line wrapper exposing `sample-size` and `mde` subcommands.
144
+
145
+ ### Notes
146
+ - Tested on Python 3.10, 3.11, 3.12.
147
+ - mSPRT formula uses `V = 2σ²/n_per_arm` with shrinkage `τ²/(V+τ²)` — a corrected
148
+ variant of an earlier draft that had an off-by-2 in the prior scaling and
149
+ inflated Type-I error to ~17% at α=0.05. Empirical Type-I error of the
150
+ shipped formula is ≤ α under H0; see `tests/test_toolkit.py::test_msprt_always_valid_type1_error`.
@@ -0,0 +1,315 @@
1
+ Metadata-Version: 2.5
2
+ Name: experiment-toolkit
3
+ Version: 0.3.0
4
+ Summary: Small, well-tested utilities for online controlled experiments: sample size, CUPED, sequential testing, delta-method variance.
5
+ Project-URL: Homepage, https://github.com/wavde/experiment-toolkit
6
+ Project-URL: Issues, https://github.com/wavde/experiment-toolkit/issues
7
+ Author: Tejas Wavde
8
+ License: MIT License
9
+
10
+ Copyright (c) 2026 Tejas Wavde
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+ License-File: LICENSE
30
+ Keywords: ab-testing,causal-inference,experimentation,statistics
31
+ Classifier: Development Status :: 4 - Beta
32
+ Classifier: Intended Audience :: Science/Research
33
+ Classifier: License :: OSI Approved :: MIT License
34
+ Classifier: Programming Language :: Python :: 3
35
+ Classifier: Programming Language :: Python :: 3.10
36
+ Classifier: Programming Language :: Python :: 3.11
37
+ Classifier: Programming Language :: Python :: 3.12
38
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
39
+ Requires-Python: >=3.10
40
+ Requires-Dist: numpy>=1.24
41
+ Requires-Dist: scipy>=1.10
42
+ Provides-Extra: data
43
+ Requires-Dist: pyarrow>=12; extra == 'data'
44
+ Provides-Extra: dev
45
+ Requires-Dist: matplotlib>=3.8; extra == 'dev'
46
+ Requires-Dist: mypy>=1.8; extra == 'dev'
47
+ Requires-Dist: pytest>=7; extra == 'dev'
48
+ Requires-Dist: ruff>=0.3; extra == 'dev'
49
+ Description-Content-Type: text/markdown
50
+
51
+ # experiment-toolkit
52
+
53
+ > Small, well-tested utilities for online controlled experiments.
54
+
55
+ ![CI](https://github.com/wavde/experiment-toolkit/actions/workflows/ci.yml/badge.svg)
56
+ [![PyPI](https://img.shields.io/pypi/v/experiment-toolkit.svg)](https://pypi.org/project/experiment-toolkit/)
57
+ [![Python](https://img.shields.io/pypi/pyversions/experiment-toolkit.svg)](https://pypi.org/project/experiment-toolkit/)
58
+ ![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)
59
+
60
+ ![hero](https://raw.githubusercontent.com/wavde/experiment-toolkit/main/docs/hero.png)
61
+
62
+ A compact Python package covering the calculations that come up in everyday experimentation work: sample sizing, variance reduction, sequential tests, ratio-metric variance, staggered DiD, sensitivity analysis for observational designs, A/B metrics scored by an LLM judge, and honest lift estimates for creatives picked by a bandit. The implementations follow standard results from the experimentation and causal-inference literature (referenced in the docstrings and below).
63
+
64
+ Intended audience: analysts, data scientists, and experimentation platform engineers who want a small, inspectable reference implementation rather than a framework.
65
+
66
+ ## Modules
67
+
68
+ | Module | Purpose |
69
+ |--------|---------|
70
+ | `sample_size` | Per-arm sample size and MDE, CUPED-aware (`rho` keyword) |
71
+ | `cuped` | Deng et al. (2013) CUPED variance reduction |
72
+ | `ratio` | Delta-method variance for ratio metrics (revenue per session, etc.) |
73
+ | `sequential` | mSPRT always-valid p-values, with optional CUPED compounding |
74
+ | `cs_did` | Callaway & Sant'Anna (2021) staggered DiD, robust to heterogeneous cohort effects |
75
+ | `sensitivity` | E-value (VanderWeele & Ding) and Rosenbaum bounds |
76
+ | `llm_judge` | LLM-judge-scored A/B metrics: naive bias/power vs. PPI++ correction with a small human-labeled sample |
77
+ | `offline_eval` | Offline LLM evals vs online A/B: mix shift, judge bias and online-only costs, with reweighting and PPI++ fixes |
78
+ | `ppi_covariates` | PPI++ plus a pre-treatment covariate (CUPED-style): closed-form label budgets and when the covariate stops helping |
79
+ | `judge_drift` | A judge that changes mid-test, flagged or silent: which analyses stay valid, why front-loaded human labels don't, and which drift monitors (judge scores, label agreement, a re-judged canary set) can detect it |
80
+ | `bandit_eval` | Lift of a creative a bandit picked from many generated variants: winner's curse, time confounding, and off-policy (IPS / SNIPS / DR) estimates from logged propensities |
81
+ | `judge_audit` | Real-data audit of an LLM judge against expert humans (MT-Bench): win-rate bias, error that depends on which model humans preferred, and PPI++ checked against a known answer |
82
+
83
+ The public API is typed (the package ships a `py.typed` marker) and unit-tested, and the key methods cite their source in the module docstrings.
84
+
85
+ ## Install
86
+
87
+ ```bash
88
+ pip install experiment-toolkit
89
+ ```
90
+
91
+ Or from source:
92
+
93
+ ```bash
94
+ pip install git+https://github.com/wavde/experiment-toolkit.git
95
+ ```
96
+
97
+ ## Quick start
98
+
99
+ ```python
100
+ from experiment_toolkit import sample_size_for_mde, apply_cuped, msprt_pvalue
101
+
102
+ # Per-arm sample size to detect a 2% lift at sd = 1.0
103
+ n = sample_size_for_mde(mde=0.02, std_dev=1.0, alpha=0.05, power=0.80)
104
+ # ~39,000 per arm
105
+
106
+ # CUPED adjustment with a pre-experiment covariate
107
+ y_adj = apply_cuped(y, pre_period_y)
108
+
109
+ # Always-valid p-value, safe to peek
110
+ p = msprt_pvalue(delta_hat=0.015, sigma=1.0, n_per_arm=5000, tau=0.05)
111
+ ```
112
+
113
+ ## CLI
114
+
115
+ The CLI exposes `sample-size` and `mde`. The other modules are library-only.
116
+
117
+ ```bash
118
+ experiment-toolkit sample-size --mde 0.02 --sd 1.0
119
+ # Required per-arm sample size: 39,244
120
+
121
+ experiment-toolkit mde --n 10000 --sd 1.0
122
+ # Detectable effect (MDE): 0.0396
123
+ ```
124
+
125
+ ## LLM-as-judge simulation
126
+
127
+ Can you ship on an A/B test whose primary metric is scored by an LLM judge? `llm_judge` simulates binary true quality plus a judge with per-arm error rates, then compares three analyses: the naive judge-only analysis, human labels only, and PPI++ (judge scores corrected with a small human-labeled sample drawn within each arm). There are no model API calls, and the ground truth is known by construction.
128
+
129
+ ```bash
130
+ pip install -e ".[dev]"
131
+ python scripts/llm_judge_sim.py
132
+ ```
133
+
134
+ The script uses a fixed seed and writes [`docs/llm_judge_results.md`](docs/llm_judge_results.md) and [`docs/llm_judge.png`](docs/llm_judge.png). Every simulated number appears next to its closed-form value. When judge noise is the same in both arms, it shrinks the effect by Youden's J and costs power. When the noise differs between arms, the naive test's false-positive rate grows with sample size. Calibration labels have to be drawn within each arm: a single shared or offline calibration cancels out of the difference.
135
+
136
+ Write-up, with the decision rule: [LLM-as-judge is a noisy metric: what it does to A/B power and bias](https://github.com/wavde/wavde/blob/main/writing/llm-judge-noise-in-ab-tests.md).
137
+
138
+ ```python
139
+ from experiment_toolkit import JudgeConfusion, simulate_judged_experiment, analyze_judged_experiment
140
+
141
+ judge = JudgeConfusion(sensitivity=0.85, specificity=0.85)
142
+ lenient = JudgeConfusion(sensitivity=0.85, specificity=0.80) # judge favours treatment
143
+ t, c = simulate_judged_experiment(5000, p_control=0.6, effect=0.0, judge_control=judge,
144
+ judge_treatment=lenient, n_labeled_per_arm=500, seed=0)
145
+ res = analyze_judged_experiment(t, c) # {"naive", "human_only", "ppi"}
146
+ ```
147
+
148
+ ## Offline evals vs online A/B
149
+
150
+ When can an offline LLM eval win be trusted to predict the online result? `offline_eval` simulates an eval set whose prompt mix differs from live traffic, a judge whose errors can differ between the baseline and candidate outputs, and online-only costs such as latency. It compares the raw offline judge score, the score reweighted to the traffic mix, judge-plus-human-labels PPI++ reweighted to the mix, and the online A/B result. There are no model API calls.
151
+
152
+ ```bash
153
+ python scripts/offline_online_sim.py
154
+ ```
155
+
156
+ The script uses a fixed seed and writes [`docs/offline_online_results.md`](docs/offline_online_results.md) and [`docs/offline_online.png`](docs/offline_online.png).
157
+
158
+ What the results show:
159
+
160
+ - Reweighting to the traffic mix fixes mix shift.
161
+ - Human labels fix judge bias.
162
+ - No offline correction can see an online-only cost.
163
+ - Each correction costs offline power, so an offline win is best used to choose what to test online, not to skip the online test.
164
+
165
+ Write-up, with the decision rule: [An offline eval win is evidence about the eval set](https://github.com/wavde/wavde/blob/main/writing/offline-evals-vs-online-ab.md).
166
+
167
+ ## PPI++ with a pre-treatment covariate
168
+
169
+ How much does a pre-treatment covariate, such as a query difficulty bucket or a user's prior-period outcome, cut the human-label budget of PPI++? `ppi_covariates` generalises PPI++ to several control variates (the judge score and the covariate). It provides the closed-form variance `Var(Y)/n · (1 − R² · N/(N+n))`, label budgets for a target power, and a simulator to check them.
170
+
171
+ ```bash
172
+ python scripts/ppi_covariates_sim.py
173
+ ```
174
+
175
+ The script uses a fixed seed and writes [`docs/ppi_covariates_results.md`](docs/ppi_covariates_results.md) and [`docs/ppi_covariates.png`](docs/ppi_covariates.png).
176
+
177
+ The covariate's gain depends on how much it adds beyond the judge. It is largest when the judge is weak, small when the judge is strong, and capped when labels are a large share of each arm.
178
+
179
+ Write-up, with the decision rule: [A covariate stacks on the judge, but a better judge beats both](https://github.com/wavde/wavde/blob/main/writing/ppi-with-covariates-label-budget.md).
180
+
181
+ ## Judge drift mid-test
182
+
183
+ What happens to a judge-scored A/B test when the judge model is upgraded partway through? `judge_drift` simulates an upgrade that switches both arms to a new judge at the same time, and compares five analyses: the judge score pooled over the test, the judge score before the upgrade only, and three PPI++ variants that differ in when human labels are drawn.
184
+
185
+ ```bash
186
+ python scripts/judge_drift_sim.py
187
+ ```
188
+
189
+ The script uses a fixed seed and writes [`docs/judge_drift_results.md`](docs/judge_drift_results.md) and [`docs/judge_drift.png`](docs/judge_drift.png).
190
+
191
+ - An upgrade that changes both arms' judged rates equally is harmless under the null.
192
+ - An upgrade that is more lenient on one arm's outputs biases the pooled judge score.
193
+ - It also biases PPI++ if all the human labels were collected before the upgrade.
194
+ - PPI++ with labels spread across the test, or stratified by judge version, stays unbiased.
195
+
196
+ Write-up, with the decision rule: [Upgrading the judge mid-test is safe only if your labels know about it](https://github.com/wavde/wavde/blob/main/writing/judge-drift-mid-test.md).
197
+
198
+ ## Silent judge drift
199
+
200
+ A hosted judge can change under the same model name, so the analysis has no version flag to stratify on. `SilentDrift` changes the judge from an unknown day, as a step or a gradual ramp, on one or both arms. It can also shift true quality with no judge change, which a drift monitor should not flag. The simulation compares the judge-only readout with PPI++ using launch-week labels or labels drawn at random from the whole test. It also runs three cheap monitors (`first_alarm`): judge pass rate on the control arm, judge pass rate on each arm, and the judge's agreement with human labels split by the human label.
201
+
202
+ ```bash
203
+ python scripts/silent_drift_sim.py
204
+ ```
205
+
206
+ The script uses a fixed seed and writes [`docs/silent_drift_results.md`](docs/silent_drift_results.md) and [`docs/silent_drift.png`](docs/silent_drift.png).
207
+
208
+ - PPI++ with labels drawn at random from the whole test stays valid under every drift tested, without knowing when or whether the judge changed. The labels can be drawn at the end from logged outputs.
209
+ - Launch-week labels and the judge-only readout are biased when drift hits one arm more than the other.
210
+ - A score monitor on the control arm can't see drift that only affects treatment. Score monitors on both arms also fire when true quality changes and the judge doesn't.
211
+ - Agreement split by the human label separates judge drift from quality change, but needs thousands of labels per arm to detect a realistic drift.
212
+
213
+ Write-up, with the decision rule: [When the judge drifts silently, random labels protect the readout and monitors only tell you where to look](https://github.com/wavde/wavde/blob/main/writing/silent-judge-drift.md).
214
+
215
+ ## Canary-set drift monitor
216
+
217
+ A canary set is a fixed set of stored outputs that the production judge re-scores every day. Their true quality can't change, so a shift in their scores can only come from the judge. `simulate_canary` re-judges stored outputs under a `SilentDrift`, with a `repeatability` setting for how often the judge repeats its verdict on the same output. `canary_alarm` compares each output's recent verdicts with its own early ones. The simulation runs it on the same scenarios as the silent-drift simulation, next to the score and agreement monitors.
218
+
219
+ ```bash
220
+ python scripts/canary_drift_sim.py
221
+ ```
222
+
223
+ The script uses a fixed seed and writes [`docs/canary_drift_results.md`](docs/canary_drift_results.md) and [`docs/canary_drift.png`](docs/canary_drift.png).
224
+
225
+ - With 400 stored outputs per arm and no human labels, the canary caught treatment-only drift about as often and as fast as a score monitor on both arms, and caught gradual drift more often.
226
+ - Unlike the score monitors, it stayed quiet when true quality fell and the judge didn't change.
227
+ - A canary built only from control outputs missed drift that affected only treatment outputs. The canary has to contain outputs from every arm.
228
+ - Closed forms give the canary size for a target detection probability (`canary_items_for_power`).
229
+
230
+ Write-up, with the decision rule: [A canary set catches a drifting judge without blaming real quality changes](https://github.com/wavde/wavde/blob/main/writing/canary-set-judge-drift.md).
231
+ ## Generated creatives picked by a bandit
232
+
233
+ Generative tools make it cheap to test 20 or 50 creative variants at once, and a bandit moves traffic toward whichever is ahead. How far is the leader's reported lift from its true lift, and which estimate from the logged decisions can be trusted? `bandit_eval` provides off-policy estimators that use the logged allocation probabilities (IPS, self-normalised IPS, doubly robust), the naive dashboard comparison, and a minimal batched Thompson-sampling log generator with known ground truth. It evaluates bandit logs; it is not a bandit framework.
234
+
235
+ ```bash
236
+ python scripts/bandit_eval_sim.py
237
+ ```
238
+
239
+ The script uses a fixed seed and writes [`docs/bandit_eval_results.md`](docs/bandit_eval_results.md) and [`docs/bandit_eval.png`](docs/bandit_eval.png). The full run takes about 33 minutes on a laptop CPU; `--smoke` takes seconds.
240
+
241
+ Two biases are at work, and they need different fixes:
242
+
243
+ - **Time confounding.** A variant that wins traffic late is measured on late traffic. With click rates drifting ±20% over the test and no variant better than control, the leader's raw lift averages +12.6% and every replication claims a win. IPS, SNIPS and DR with the logged propensities remove this part.
244
+ - **Winner's curse.** The leader was chosen because its estimate was high. IPS on the same log still overstates it: by +4.6 pp with 20 null variants (about 22% false wins at a nominal 2.5%), and DR on the same log by +8.0 pp with 50. When variant lifts are spread around zero (SD 4%) and clicks drift, the leader's true lift is +5.7% while the same-log IPS estimate is +7.7% and the raw lift +16.3%.
245
+
246
+ What the simulation shows about the fixes:
247
+
248
+ - **Splitting the log after the fact doesn't work.** The bandit allocated traffic using both halves, so the held-out half is biased (here downward) and the variant it picks is worse.
249
+ - **Data the bandit never learned from does.** A 20% evaluation slice that the bandit serves but never updates on, and a 50k-per-arm confirmation A/B, are both unbiased with 94–96% coverage. The slice barely hurts the pick, but its SE is 2.3–2.8× the confirmation test's at a similar impression count, because most of its traffic went to variants that lost.
250
+
251
+ Decision rule: let the bandit choose, but quote the lift only from impressions it didn't learn from. Run a short confirmation A/B when the number feeds a ship or forecast decision. If no extra time is available, reserve an evaluation slice from day one and log propensities with a floor, and treat it as a check on direction and rough size. Never report the leader's raw lift, and don't treat IPS on the same log as a fix for the winner's curse.
252
+
253
+ ```python
254
+ from experiment_toolkit.bandit_eval import ope_lift
255
+
256
+ # One row per impression: arm shown (0 = control), click, logged probability of that arm.
257
+ # Rows from the evaluation slice only, for the leader chosen on the other rows.
258
+ res = ope_lift(arms[slice_], clicks[slice_], propensity[slice_], target=leader, control=0)
259
+ res.estimate, res.ci()
260
+ ```
261
+
262
+ Where this breaks: with two to five variants the same-log overstatement is under 2 pp, so the extra machinery buys little. A thin propensity floor (≤1% of variant traffic) drops the slice's coverage to 0.91–0.93. Lifts are held constant over time; if generated creatives have a novelty effect that fades, no estimate from the test window measures the post-launch lift, and only a later confirmation test does.
263
+
264
+ Write-up: [Classic case studies, reread in 2026](https://github.com/wavde/wavde/blob/main/writing/classic-case-studies-reread-2026.md).
265
+
266
+ ## Real-data judge audit (MT-Bench)
267
+
268
+ Every LLM-judge simulation above assumes a judge whose errors can depend on which arm produced the output. `judge_audit` checks that on real data: the public [MT-Bench human judgments](https://huggingface.co/datasets/lmsys/mt_bench_human_judgments) (Zheng et al., 2023, CC BY 4.0), where expert humans and GPT-4 judged the same pairwise comparisons of six models. Each pair of models is read as a side-by-side test, with the stronger model as treatment.
269
+
270
+ ```bash
271
+ pip install -e ".[dev,data]"
272
+ python scripts/judge_audit_mtbench.py
273
+ ```
274
+
275
+ The data (about 1.4 MB) are downloaded on first run from a pinned revision, checked against SHA-256 hashes and cached in `data/mt_bench/`; they aren't committed. The script uses a fixed seed and writes [`docs/judge_audit_results.md`](docs/judge_audit_results.md) and [`docs/judge_audit.png`](docs/judge_audit.png). CI smoke-runs it on synthetic data with the same schema.
276
+
277
+ - GPT-4's win rate for the stronger model was above the experts' in all 15 pairs, by up to +0.185, on the same items.
278
+ - When experts preferred the stronger model, GPT-4 agreed 82% of the time; when they preferred the weaker one, 22%. The judge's error depends on the arm.
279
+ - In a known-answer check that resamples the real verdicts, with 200 human labels per pair, PPI++ kept 93–96% coverage. The judge alone covered the truth in at most 0.5% of replications in 13 of 15 pairs, and at most 44% in the other two.
280
+ - The real judge correlates with humans far less than the simulated judges assumed (0.14–0.56 against 0.69), so PPI++ saved only 2–28% of labels.
281
+
282
+ Write-up, with the decision rule: [A real LLM judge favours the winner: auditing GPT-4 against expert humans](https://github.com/wavde/wavde/blob/main/writing/real-judge-audit-mt-bench.md).
283
+
284
+ ## Out of scope
285
+
286
+ Not in this package: a bandit framework (`bandit_eval` only evaluates logged bandit traffic; its simulator is a minimal test fixture), a Bayesian posterior sampler, a full experimentation platform, assignment or exposure logging, multiple-comparison correction beyond what the sequential tests provide. Those belong in separate layers.
287
+
288
+ ## Development
289
+
290
+ ```bash
291
+ pip install -e ".[dev]"
292
+ pytest
293
+ ruff check .
294
+ ```
295
+
296
+ ## References
297
+
298
+ - Deng, Xu, Kohavi, Walker (2013). CUPED.
299
+ - Deng, Knoblich, Lu (2018). Delta method in metric analytics.
300
+ - Johari, Pekelis, Walsh (2015). Always-valid inference.
301
+ - Callaway & Sant'Anna (2021). Difference-in-differences with multiple time periods.
302
+ - VanderWeele & Ding (2017). Sensitivity analysis in observational research.
303
+ - Kohavi, Tang, Xu (2020). *Trustworthy Online Controlled Experiments.*
304
+ - Angelopoulos, Bates, Fannjiang, Jordan, Zrnic (2023). Prediction-powered inference.
305
+ - Angelopoulos, Duchi, Zrnic (2023). PPI++: Efficient prediction-powered inference.
306
+ - Chaganty, Mussmann, Liang (2018). The price of debiasing automatic metrics in natural language evaluation.
307
+ - Dudík, Langford, Li (2011). Doubly robust policy evaluation and learning.
308
+ - Swaminathan & Joachims (2015). The self-normalized estimator for counterfactual learning.
309
+ - Nie, Tian, Taylor, Zou (2018). Why adaptively collected data have negative bias and how to correct for it.
310
+ - Hadad, Hirshberg, Zhan, Wager, Athey (2021). Confidence intervals for policy evaluation in adaptive experiments.
311
+ - Andrews, Kitagawa, McCloskey (2024). Inference on winners.
312
+
313
+ ## License
314
+
315
+ MIT. See [LICENSE](LICENSE).