
Reproducing the delivered manuscript and the decisions that move the numbers
Source:vignettes/reproducing_the_manuscript.Rmd
reproducing_the_manuscript.RmdWhat “similar” means, the open differences, and every decision that changes the published numbers.
Code blocks on this page are illustrative and are not run when the package is built. R and Python examples are labelled; a feature marked “Python only” has no R counterpart.
The package is meant to be the thing delivered going forward: the default federated cohort (one random stay per patient, 2017-01-01 to 2022-09-30, 50/50 balanced training), the standard OHDSI features and the eDERRI features Dr. Rubin asked for, and the tables, listings and figures of the current manuscript. “The defaults give results very similar to the ones we already have” is a claim that has to be measured, so this section records the measurement and the rule.
Timed run with repo defaults
(scripts/reproduce_study.py, 5 sites, N = 225,939, 100
bootstraps): 4,086 s, about 68 minutes (per-site extraction 40 s to
1,274 s depending on site size, tables and figures 1,240 s). The sample
was not pinned, so it is a fresh random draw.
What was found when that run was compared with the delivered
workbook (compare_workbooks counts every cell that
moved):
| Sheet | Cells that differ | Reading |
|---|---|---|
| Table 2, Table 4 | 0 | Identical. Every Table 2 AUC is within 0.001 of the delivered value. |
| Table 1 | 29 of 189 | Small: median relative difference about 2%. |
| Table 3, S1, S2 | 3 of 72, 17 of 84, 9 of 63 | Small. |
| Table 5 | 23 of 25 | Mostly a labelling and metric issue, see below. |
| Table 6 | 126 of 281 | Real. P-values move most; the SDI and RUCA terms drive it. |
| Table S3 | 75 of 277 | Follows the site labels, plus one extra row. |
| Tables 6, S3, S4 | one extra row each | The SDI Quintile: Missing / Unknown term and the new
attrition step. |
Three causes were separated:
-
Site labels. The delivered workbook uses anonymous
labels (Site A to E) that are not the command-line order, so the run’s
“Site A” was a different health system and Table 5 and S3 rows were
compared against the wrong sites. The site-to-label mapping is
deliberately not stored in this repository, because
publishing it would identify the sites in the manuscript.
run_study(site_labels={...})takes it from the caller; keep that mapping in a private, untracked file. Without it the labels areSite A, B, ...in command-line order. -
Table 5 used a different model and balancing from the
delivered table (found and fixed). The delivered Table 5 comes
from
pipeline/evaluate_loso_harmonized.py: the F1-tuned XGBoost (300 trees, learning rate 0.05, depth 6), trained on the other four sites with the minority class upsampled with replacement to 50/50 (the rule of Tables 2 to 4), median imputation fitted on the training sites, scored at the 0.5 threshold on the natural held-out site with no calibration. The package’s leave-one-site-out used HistGBM and undersampled the majority class, so sensitivity, specificity and Brier (and the largest site, below) moved. This was established by running the legacy script on the legacy feature file (it reproduces the delivered Table 5 to the third decimal) and then the package on the same file: with the old balancing the package gave an AUC of 0.713 at the largest site and sensitivity 0.598; withbalance_method="upsample"and the tuned XGBoost it reproduces all five delivered rows exactly (AUC, Brier, sensitivity, specificity).build_study_tables(loso_model="tuned_xgboost")is now the default (the XGBoost configuration chosen by F1 in Table 3, upsampled, median-imputed;"hist_gbm"keeps the previous model) andevaluate_loso_transporthas abalance_methodargument ("undersample"default,"upsample"). The “manuscript” Table 5 option (0.5 threshold, uncalibrated) is the delivered rule; “calibrated” is an alternative view, not what was delivered. - The largest site in Table 5. Its delivered AUC of 0.687 (and low sensitivity, 0.364) is not a feature problem; it is what the upsampled tuned XGBoost gives when the largest site is held out. The package reproduces it exactly on the legacy feature file. The first full run with the new default has not been done yet.
The rule for “similar”.
omop_etl.workbook_similarity(new, old) returns one
pass/fail row per check, with the thresholds in
SIMILARITY_TOLERANCES. run_study writes it as
<prefix>_Similarity.csv when compare_to
is given.
| Check | Default threshold | Result on the unpinned default run (sites paired as delivered) |
|---|---|---|
| Table 2 AUC, every model | within 0.01 | pass (worst 0.001) |
| Table 5 AUC, every site | within 0.02 | fail on the first run (4 of 5; the largest site differs by 0.032) because of the model and balancing in item 2; exact on the legacy feature file after the fix |
| Table 6 odds ratio | within 10% relative, for 95% of rows | pass (96.5%) |
| Table 6 direction (old OR outside 0.97 to 1.03) | agrees for 95% of rows | pass (98.1%) |
| Table 6 p < 0.05 verdict | agrees for 95% of rows | fail (86%; the 12 disagreements are SDI quintiles, RUCA, smoking, beta blockers, corticosteroids, CKD, diabetes, HIV and overweight BMI) |
| Table 6 rows missing from the new workbook | none | pass |
| Table 1 cells | within 5% for 90% of cells | pass (97.9%) |
The thresholds are a proposal; nothing here has been agreed with
Dr. Rubin. Change them in one place (SIMILARITY_TOLERANCES)
once they are. The check is a regression gate: it says how far two
workbooks are apart, not which one is right. The Table 5 line above was
computed after re-labelling the saved workbook; the next full run will
use the manuscript labels directly.
Reading of the result: the model-performance story reproduces (Table
2 to 0.001) and the cross-site story reproduces for four of five sites.
What does not reproduce is which Table 6 covariates are significant,
mostly the area-level (SDI, RUCA) terms. That is consistent with the
address tie_break choice and with a fresh random sample,
and it is untested which of the two it is. The next step is a run with
the stays pinned (pin_stays) to separate sampling noise
from definition changes. If the pinned run matches Table 6, the
remaining gap is sampling, and the manuscript profile should ship a
pinned stay list or a seed manifest.
Decisions that move the numbers, and how to recreate or change each
Several choices made while reproducing the delivered manuscript
change the published numbers. None is hard-wired: each is an option with
a name, a list of values and a record in
<prefix>_run.json (decisions).
python scripts/reproduce_study.py --list-decisions prints
them; omop_etl.STUDY_DECISIONS and
omop_etl.STUDY_PRESETS hold the same in code.
Since 0.32.0 the package preset follows the November 11
deliverable except where that deliverable was wrong: lab and vital
definitions from the vocabulary hierarchy (concept_sets), a
“not measured” term instead of median imputation alone
(table6_missing), an SDI-missing term (without it, stays
with no SDI join the reference quintile), a CONSORT table that ends at
the analysed cohort (consort_final_steps), and dated
addresses ranked ahead of undated ones (the delivered order came from an
operator-precedence slip, address_undated).
Decision (run_study argument) |
Options |
package preset |
delivered_2026_11_11 preset |
Effect |
|---|---|---|---|---|
address_tie_break |
deterministic, highest_zip,
ambiguous_missing, arbitrary,
first_listed
|
first_listed |
first_listed |
Which ZIP wins when addresses tie on every rule key.
first_listed takes the address stored first in the address
table (location_id), which is what a stable pandas sort
does; it is the same on every run. arbitrary is engine
order and is not reproducible. |
address_undated |
last, first
|
last |
first |
Rank of an address with no start date among those in effect. The
study’s pandas pipeline ranks it ahead of every dated address (an
operator-precedence quirk in index_address);
last is the documented rule. |
sdi_missing_term |
True, False
|
True |
False |
False leaves the SDI-missing term out of Table 6, as
the delivered workbook did. |
table5 |
manuscript, calibrated
|
manuscript |
manuscript |
Delivered rule: tuned XGBoost, 50/50 upsampled training, 0.5 threshold, uncalibrated. |
attrition_mode |
windowed, full_history
|
full_history |
full_history |
CONSORT layout (Table S3). |
consort_final_steps |
True, False
|
True |
False |
Table S3 ends with the window / one-stay and pinned-list steps, or with the last eligibility rule. |
table6_increments |
sd, clinical
|
clinical |
clinical |
Continuous Table 6 rows per 1 SD, or per 10 mmHg, 30 days, 5 mEq/L
and so on (CLINICAL_INCREMENTS; a mapping
label -> (text, size) gives your own). Same model:
p-values and standardised betas do not change. |
concept_sets |
bundled, legacy_2026_11_11, or an exact
bundled version |
bundled |
legacy_2026_11_11 |
Lab and vital definitions. legacy_2026_11_11 is the
plain LOINC lists of 0.20.0 to 0.28.1 (no troponin I, lactate, pCO2 or
pO2, no 0.29.0 code expansion), so a rerun compares with the delivered
workbook without feature-definition changes. An exact version fails on a
release that ships another. |
table6_missing |
indicator, median
|
indicator |
median |
How a continuous Table 6 measure with missing values enters.
indicator adds a “not measured” (labs, vitals) or “missing”
term under it and estimates the measure’s OR from the stays where it was
measured; median imputes the median only, which treats
every unmeasured stay as typical and pulls the OR of a mostly-unmeasured
lab (lactate, troponin I, pCO2, pO2) towards 1. Measures with fewer than
11 missing stays are median imputed either way. |
Other choices with their own switch: pinned_stays (reuse
the delivered stay-per-patient draw, or leave unset for a fresh random
draw), sites and site_labels (the label
mapping is supplied by the caller and never stored in the repository),
sheet_site_labels (relabel Tables S1 and S3 only: the
delivered workbook labels the sites one way in Table 5 and another in S1
and S3; on the command line --s1-s3-labels), the date
window (start, end),
cohort_params, profile (ederri,
both, none), n_bootstraps,
min_cell, SIMILARITY_TOLERANCES, and in
build_study_tables loso_model
(tuned_xgboost, hist_gbm) with
evaluate_loso_transport(balance_method=). In R:
derive_geography_features(tie_break=, undated=) and
extract_benchmark_features(address_tie_break=, address_undated=).
python scripts/reproduce_study.py --db-dir derived/omop_duckdb --out out --sites A B C --preset delivered_2026_11_11 \
--pinned-stays selected_stays.csv --tie-break deterministic # the delivered recipe, with one decision changedWhy the delivered Table 6 differed in the SDI and RUCA rows,
and what fixed it. The regression code was right: given the
legacy feature file,
manuscript_regression(sdi_missing_term=False) reproduces
every delivered Table 6 row. The difference was the per-patient
geography. With the stays pinned, the package’s documented address rule
disagreed with the delivered SDI quintile for 22,440 stays at one site,
2,297 at another and 29 at a third; arbitrary agreed only
in the totals. first_listed +
address_undated="first" gives 0 differing SDI quintiles and
0 differing RUCA categories at all five sites (225,939 stays).
Measured: pinned stays + delivered_2026_11_11 +
--s1-s3-labels (5 sites, N = 225,939, 100 bootstraps, 69
minutes plus a 17-minute re-run of the tables). Cells that
differ from the November 11 workbook, with
compare_workbooks tolerances (0.01 absolute and 2%
relative): Tables 1, 2, 4, S1 and S2: 0. Table 6: 2 of 281 (BUN
standardised beta 0.13 against 0.12, eGFR p 0.578 against 0.563; three
stays have a different eGFR in the legacy file). Table 3: 1 of 72 (the
logistic-regression AUC-tuned row picked C=0.01 instead of
the near-tied C=0.1). Table 5: 3 of 29, all sensitivities
(Site C 0.385 against 0.364); every AUC is within 0.003. Table S3: 50 of
252, all in the per-site rows: the delivered per-site table has ten
steps, with the “not metformin-only” step listed twice (steps 7 and 8,
same count), so its later steps are one number off from the combined
table, which has nine; the package keeps nine for every site.
workbook_similarity passes every check at 100% (worst Table
2 AUC difference 0.002, worst Table 6 odds-ratio difference 1.1%, all 86
p < 0.05 verdicts agree). Reproduce the table with
scripts/check_golden.py --new ... --golden ... --deltas deltas.csv.
Anonymous site letters.
run_study(site_labels="random") (or
--labels random) gives each site a random letter, so “Site
A” does not follow the order the sites were typed in;
label_seed / --label-seed makes the draw
repeatable, "ordered" follows the command line, and a JSON
file written by save_site_labels() (labels_out
/ --labels-out) is read back with
site_labels=<path>. The mapping is never written to
the workbook or to <prefix>_run.json (which holds
only the list of labels): keep the file outside the repository and the
shared results. For a consortium, assign the letters once at the
coordinating centre and give each site its own, otherwise every site’s
“Site A” is a different system.
assign_site_labels(sites, mode=, seed=) returns the mapping
without running anything.
Golden workbook.
tests/golden/synthetic_manuscript_tables.xlsx is a
committed workbook built from a seeded synthetic cohort;
tests/test_golden_workbook.py fails when any cell moves and
shows that a changed decision is caught. Regenerate it on purpose with
OMOP_GOLDEN_UPDATE=1 pytest tests/test_golden_workbook.py.
scripts/check_golden.py does the same against a real
delivered workbook (not in the repository).
workbook_deltas() / delta_summary() list the
cells and rows that moved, sorted by relative change;
run_study(compare_to=) writes them as
<prefix>_Deltas.csv and
<prefix>_Delta_Rows.csv.
Results report.
scripts/render_manuscript.py --workbook ... --out ...
(omop_etl.render_results_report) writes
manuscript_facts.json (cohort size, readmission rate, AUC
ranges, site sizes), one CSV per table, Results.md and a
self-contained Results.html, so the numbers a text quotes
come from the run. It does not render the Quarto manuscript, whose
narrative modules (manuscript_params_grant_scoped.py) live
outside this repository.