Separating Model Failure from Coding Failure in External Validation

When a clinical prediction model is tested at a new hospital, the outcome labels used to grade it usually come from billing codes, the diagnosis codes hospitals assign for reimbursement. Those codes are a poor and site-specific stand-in for what actually happened to the patient. In an audit of 243,922 admissions, codes for seven lab-definable conditions were almost never wrong when present (mean specificity 0.984) but missed about 80% of true cases (mean sensitivity 0.203). With identical lab-confirmed hyperkalemia, a patient at one hospital had 18.4 times higher odds of being coded than at another (Characterizing the limitations of using diagnosis codes in the context of machine learning for healthcare). An external validation that scores a model against the new site's codes therefore measures two things at once: whether the model transports, and how that hospital happens to code. A drop in performance on the code labels does not tell you which of the two happened, and so it does not tell you whether to deploy, recalibrate, or retrain.

We propose to separate the two. At the target hospital, a small audit sample is labeled with true outcomes, through lab criteria or chart review. From it we fit a model of that hospital's coding behavior, meaning how likely a true case is to receive a code given the patient's features. That coding model is then used to correct the model's discrimination and calibration as measured on all the code-labeled patients. The output is an estimate of how well the model would perform against true outcomes, together with a rule for deciding whether the gap calls for local adaptation. We test this on conditions where lab values give the truth for every patient, so the correction can be checked exactly, and we hide those labels everywhere except the audit sample to mimic the common case where truth is expensive.

Core Claim

External-validation drops measured on administrative labels are partly an artifact of the target site's coding sensitivity. A coding model estimated from a few hundred audited patients can recover the true external area under the ROC curve (AUROC, the probability the model ranks a random true case above a random non-case) and the true calibration well enough to change deployment decisions. Write $y$ for the true outcome, $z$ for the code label, $x$ for patient features, and $t$ for the target site. Because coding specificity is near one, the observed code rate factors approximately as

$$P(z=1 \mid x,t) \approx s_t(x)\, P(y=1 \mid x,t),$$

where $s_t(x)=P(z=1\mid y=1,x,t)$ is the site's coding sensitivity. This sensitivity may depend on severity, care unit, or length of stay, not just on a constant per hospital.

Given $s_t$, each uncoded patient in the target data is a true case with probability

$$w(x)=\frac{(1-s_t(x))\,p(x)}{1-s_t(x)\,p(x)},$$

where $p(x)=P(y=1\mid x,t)$. AUROC and calibration can then be computed as weighted pair and bin statistics. This framing borrows from positive-unlabeled learning, but the "selected completely at random" assumption that learning usually makes is exactly what institutional coding personalities violate. Estimating a feature-dependent $s_t(x)$ from an audit sample is the part that is new.

Relation to Prior Work

The motivating evidence comes from three papers. Characterizing the limitations of using diagnosis codes measures code–lab disagreement across SickKids and Stanford, but it trains no models and offers no correction for transfer. We turn its descriptive finding into an estimator. Evaluating the performance and potential bias of predictive models for detection of transthyretin cardiac amyloidosis shows a claims-based random forest at AUROC 0.49 externally, against 0.88–0.92 for echo-video models. Development and validation of a prognostic model predicting symptomatic hemorrhagic transformation shows a model mapped to the shared OMOP vocabulary falling from 0.75 internally to 0.50 on a German outpatient database. Neither study asks how much of the collapse lies in the labels and features versus the model, and that question is ours.

Two other papers constrain the design. All models are local argues for recurrent local validation, citing the Epic Sepsis Model's fall to 0.60–0.64. We agree that validation should be local. Our point is that local validation against local codes inherits local coding bias, so a site-specific correction is needed for local validation to mean anything. A Cross-institutional Evaluation on Breast Cancer Phenotyping NLP Algorithms shows that fine-tuning at the target site closed a residual gap (micro-F1 0.925 versus 0.932 native). Its labels were manually annotated, not billing-derived, which is the luxury our audit sample tries to approximate cheaply.

EHRSHOT and Cross-Representation Benchmarking supply the models and data: a pretrained patient-sequence model (CLMBR-T-base) and count-based gradient boosting, evaluated on Stanford and MIMIC-IV records. Neither tests transport across coding regimes.

Research Program

The first component is a two-site testbed with lab-defined truth. We take MIMIC-IV (Beth Israel Deaconess) and the EHRSHOT Stanford cohort, both of which contain lab values and ICD codes. In each we define acute kidney injury, hyperkalemia, hyponatremia, hypoglycemia, anemia, neutropenia, and thrombocytopenia using the lab thresholds of Guo et al. We also define the matching code labels. As in that paper, we expect high specificity and low, site-varying sensitivity.

Predictors are trained using only features available before the outcome window, so the lab criterion is never an input. Each model is trained at one site on code labels, which is what practitioners do, and validated at the other site. If the SickKids and Stanford pediatric cohorts become available through collaboration, they form a third and harsher pair, since they have the documented 18.4-fold discrepancy.

The second component is the coding-model estimator. We draw audit samples of 50, 100, 200, and 500 target-site patients, reveal their lab truth, and fit $s_t(x)$ with a small regularized logistic model. Its inputs are a handful of interpretable covariates: lab severity proxy, care unit, length of stay, and encounter type. We combine $s_t$ with the transported model's own $p(x)$, after a single-parameter recalibration on the audit sample, to compute corrected AUROC, calibration slope, and expected calibration error. Uncertainty comes from bootstrapping over the audit draw.

The third component is a decision rule for "deploy as-is versus adapt locally," the gap All models are local leaves open. The rule triggers adaptation when the corrected true-label AUROC at the target falls below the source internal AUROC by more than a margin, with the margin set on held-out condition–site pairs. It is scored against an oracle that knows, from full lab labels, whether target-site fine-tuning on true labels actually helps.

A secondary component is training-time use of the same factorization. A model with a shared disease head and a per-site coding head would be trained on code labels pooled from both sites. If the factorization is right, the shared head should transport better against true labels than a model trained on pooled codes.

Baselines

The naive reference point is standard external validation: freeze the source model, score it against target-site code labels, and report AUROC and calibration. This is what the OHDSI and amyloidosis studies report. Our estimator beats it if its estimate of true-label AUROC is closer to the oracle value computed from all lab labels.

The strongest practical competitor is audit-only validation, which computes AUROC directly on the audited patients with true labels and ignores the code-labeled bulk. It is unbiased, so our method is justified only if it reduces variance enough to matter. Both methods get the same audit draws and the same bootstrap, and our method must yield a narrower interval at matched or smaller absolute error at audit sizes of 200 or fewer.

A second competitor is the classical positive-unlabeled correction with a constant per-site sensitivity estimated from the same audit. Comparing against it isolates the key ingredient: a feature-dependent coding sensitivity. If the constant version does as well, the institutional-personality story reduces to a single number per site, and the proposal shrinks accordingly.

For the training-time component, four baselines share the same splits, the same features, and an equal hyperparameter search of 50 trials per method:

  • count-based XGBoost and the released CLMBR-T-base trained on pooled codes;
  • the adversarial sample–enhanced domain adaptation of Adversarial Sample Enhanced Domain Adaptation, which raised Male→Female MIMIC-III mortality AUROC from about 0.799 to 0.834;
  • target-site fine-tuning on target codes;
  • an oracle trained on lab labels, which serves as a ceiling.

On reference numbers: EHRSHOT reports CLMBR at 30-day readmission F1 of 0.335 against 0.266 for the count baseline, and Cross-Representation Benchmarking reports CLMBR ICU mortality AUROC of 0.857. For transfer of lab-defined conditions trained on codes between MIMIC-IV and Stanford, I found no reported result on Lacuna, so our baselines establish those numbers.

Why not just…?

Why not just use lab values as labels? For these seven conditions one should, and that is precisely why we use them: they let us grade the estimator exactly. The estimator is meant for the many outcomes, such as amyloidosis, sepsis, or hemorrhagic transformation, where truth requires chart review. The experiment that matters is whether the correction generalizes across conditions. We fit the decision margin on some conditions and test it on held-out ones, which simulates applying it to an outcome without a lab definition. A small chart-reviewed sample for one non-lab outcome in MIMIC-IV would be the follow-up check.

Why not just harmonize to OMOP? Shared vocabularies standardize what codes mean, not whether they get assigned. The OHDSI hemorrhagic-transformation model was fully OMOP-mapped and still reached AUROC 0.50 on one database (Development and validation…). Both of our sites will be in OMOP-style formats, so any remaining gap is coding behavior by construction.

Why not just recalibrate locally, or fine-tune on local codes? Recalibrating to local codes calibrates the model to the local coding rate, which per Guo et al. can be roughly one-fifth of the true rate, so the model looks calibrated while underestimating risk. Fine-tuning on local codes teaches the model the local coding personality. Both are real threats only if coding sensitivity is close to constant within a site, because then a constant rescaling plus the audit would suffice. The constant-sensitivity baseline tests exactly this, and we will report it honestly.

Why not just use the audited patients alone? This is the strongest objection. With 500 audited patients and a common condition, audit-only AUROC may be precise enough, and our method then adds little. We expect the benefit at small audits and for rare outcomes, and we will chart the crossover audit size rather than claim uniform gains.

Proposed Experiments

The decisive check is a curve over audit sizes. For every condition and direction of transfer (MIMIC-IV to Stanford and back), we plot absolute error and interval width of the estimated true-label AUROC and calibration slope for four methods: naive code-label validation, audit-only, constant-sensitivity correction, and feature-dependent correction. All are measured against the lab-label oracle.

Two further checks follow. The first is the deploy-versus-adapt rule, scored by agreement with the oracle decision on held-out conditions. The second is a semi-synthetic stress test. We split MIMIC-IV by care unit, impose known coding channels with sensitivities ranging from 0.1 to 0.9 that depend on severity, and confirm that the estimator recovers truth when the generating mechanism is known.

The proposal fails if any one of three things happens: naive code-label drops track the oracle drops closely, the constant-sensitivity correction matches the feature-dependent one, or audit-only validation dominates at 100 patients. Any of these would be a useful negative result. It would mean that code-labeled external validation, or a cheap audit alone, is already trustworthy.