
Post-deployment drift and calibration monitoring
Source:R/monitoring.R
population_stability_index.Rdpopulation_stability_index() compares the predicted-risk distribution with a frozen baseline over the baseline's quantile
bins (outer bins open-ended; empty bins floored at 1e-4). Rule of thumb: < 0.10 stable, 0.10-0.25 watch, >= 0.25 shifted.
calibration_summary() gives observed vs predicted for scored encounters with known outcomes. monitor_scores() builds a monthly
table, and update_monitoring_log() upserts it into a CSV. Output is aggregate-only. Mirror of Python omop_etl.monitoring.
Usage
population_stability_index(baseline, current, bins = 10)
calibration_summary(y, p, bins = 10, min_events = 30)
monitor_scores(
scores,
baseline_prob,
date_col = "score_date",
prob_col = "prob",
outcome_col = "outcome_flag",
as_of = NULL,
followup_days = 30,
min_events = 30,
psi_bins = 10,
oe_range = c(0.8, 1.25),
slope_range = c(0.8, 1.2)
)
update_monitoring_log(report, path, model_version = "")Arguments
- baseline
Frozen reference probabilities (e.g. validation-period scores).
- current
Probabilities to compare.
- bins
Number of quantile bins.
- y
0/1 outcomes.
- p
Predicted probabilities.
- min_events
Minimum events AND non-events before slope, intercept and AUROC are reported (else
NA).- scores
A data.frame with the score date, the probability and (optionally) the 0/1 outcome.
- baseline_prob
Frozen reference distribution for the PSI.
- date_col, prob_col, outcome_col
Column names (
outcome_col = NULLfor none).- as_of
Date the report is run (default today); a month's calibration is computed only once month end +
followup_days<=as_of.- followup_days
Outcome window in days.
- psi_bins
Bins for the PSI.
- oe_range, slope_range
Acceptable observed/expected ratio and calibration slope; outside them (with >=
min_eventsevents) the month is"miscalibrated".- report
The data.frame from
monitor_scores().- path
CSV log path.
- model_version
Version string; the log is keyed on (
model_version,month).
Value
population_stability_index(): a number.
calibration_summary(): a list with n, events, observed, mean_predicted, oe_ratio, brier, ece, slope,
intercept, auroc.
monitor_scores(): a data.frame with one row per month (month, n, mean_prob, psi, outcomes_matured,
n_with_outcome, the calibration_summary() fields and status: ok, watch (PSI 0.10-0.25), drift (PSI >= 0.25),
miscalibrated or insufficient_outcomes; miscalibrated takes precedence).
update_monitoring_log(): the full, sorted log (a later run replaces a month, e.g. once its outcomes mature).