Build a reproducible report that separates overdue gaps, selection, prediction-time imputation and unseen-outcome uncertainty.
Project: audit missing delivery scans before reporting service rates
Create a defensible fixture
Use 47 eligible dispatched parcels split into 20 partner and 27 ordinary parcels. Mark eight partner and one ordinary final scans as missing after a declared grace window. Give every parcel a carrier, dispatch time, expected scan deadline and known pre-dispatch queue time when available. Keep scan events separate from the parcel dimension so duplicate retries and late arrivals are visible. The observation-process lesson guides the status definitions.
Validate the cohort
Assert that exactly 47 parcels enter the target population and that nine are overdue without a final scan. Count missing rates within carrier and day, including both numerator and denominator. Add a not-yet-due parcel to the raw fixture and prove it is excluded from the overdue-gap count. Reconcile the parcel dimension with the event stream before calculating any late rates.
Quantify selection
Show that complete-case deletion leaves 38 parcels, with partner share 12/38 rather than 20/47. Use seven observed late deliveries as a separate illustrative outcome fixture and calculate the assumption-free late-rate bounds 7/47 and 16/47. Label the observed-subset rate 7/38. The selection lesson explains why those three numbers answer different questions.
Build a leakage-safe prediction baseline
For a separate delay-prediction exercise, fit the queue-time replacement from training dates only. Keep a missingness flag and apply the stored value to future dates. Compare validation performance with a feature-omission baseline. Do not feed final scans into a pre-dispatch model. The imputation lesson supplies a small executable contract.
Publish the decision packet
Plot implied all-parcel late rates as the assumed unseen late share moves from zero to one, and mark the 25% service threshold. Record the tipping share, carrier-specific gap rates, event cutoff, code revision, excluded counts and unresolved data-quality questions. After late events arrive, compare their outcomes with the assumptions and update the next report. Sensitivity analysis remains visible alongside the point estimate.
Implementation
def report_counts(eligible_parcels, overdue_missing, observed_late):
observed = eligible_parcels - overdue_missing
if observed <= 0 or overdue_missing < 0 or not 0 <= observed_late <= observed:
raise ValueError("invalid parcel counts")
return {"observed": observed,
"observed_late_share": observed_late / observed,
"all_parcel_lower": observed_late / eligible_parcels,
"all_parcel_upper": (observed_late + overdue_missing) / eligible_parcels}
packet = report_counts(47, 9, 7)
assert packet["observed"] == 38
assert round(packet["all_parcel_upper"], 3) == 0.340Performance and operating cost
Count aggregation is O(N) over N parcels, or O(N + E) if E scan events need reconciliation. The final packet calculation is O(1). Review effort should focus on cohort eligibility, timestamps and missingness assumptions rather than the arithmetic.
Common Mistakes
- Do not mix not-yet-due and overdue scans.
- Do not use a post-dispatch outcome as a pre-dispatch feature.
- Do not publish the observed-subset late share as the all-parcel service rate.
Read next
- Missingness mechanisms: model why a value is absent
- Complete-case selection: know whose outcome remains
- Train-only imputation and missingness indicators
- Missing-not-at-random sensitivity: test what unseen outcomes could change
Continue the workflow: Project: audit a refund service result with missing final outcomes.
