Rare Events Toolkit (Penalization, Calibration, Reporting)

Toolkit
Rare Events Toolkit
A practical toolkit for rare-outcome modeling, including event-rate diagnostics, penalized logistic regression, precision-recall evaluation, calibration checks, and reporting templates.
Published

March 23, 2026

Modified

June 9, 2026

Executive Summary

This toolkit is a reusable framework for modeling rare clinical outcomes when instability, separation, poor calibration, and misleading performance summaries are likely risks.

It includes:

  • event-rate diagnostics
  • a rare-events modeling checklist
  • penalized logistic regression templates
  • probability-focused evaluation code
  • calibration and threshold guidance
  • reviewer-facing reporting language

Rare outcomes require more than a standard logistic regression run and an AUROC table. When events are scarce, the workflow must become more deliberate about bias, optimism, calibration, and decision relevance (King and Zeng 2001; Steyerberg 2019; Harrell 2015).


1. Why Rare Events Need a Different Workflow

Rare-event settings create predictable problems:

  • coefficient instability
  • complete or quasi-complete separation
  • poor calibration despite reasonable discrimination
  • misleading accuracy metrics driven by the majority class
  • large uncertainty in subgroup or site-specific estimates

That is why rare-event modeling should be treated as a distinct workflow rather than as ordinary logistic regression with a smaller event count (King and Zeng 2001; Harrell 2015).

A useful first calculation is the event fraction:

\[ \text{Event fraction} = \frac{\sum_i y_i}{n} \]

When this fraction is very small, both modeling and evaluation need to adapt.


2. Setup and Minimum Data Checks

Assume an analysis dataset named data with:

  • outcome coded 0/1
  • candidate predictors already cleaned
  • one row per analytic unit
required_pkgs <- c("dplyr", "tibble", "ggplot2")
missing_pkgs <- required_pkgs[
  !vapply(required_pkgs, requireNamespace, logical(1), quietly = TRUE)
]

if (length(missing_pkgs) > 0) {
  stop("Missing packages: ", paste(missing_pkgs, collapse = ", "))
}

# Example:
# data <- readRDS("data_processed/analysis_df.rds")
# stopifnot(all(c("outcome") %in% names(data)))

Quick event-rate summary:

rare_event_summary <- function(df, outcome) {
  y <- df[[outcome]]
  tibble::tibble(
    n = length(y),
    n_events = sum(y == 1, na.rm = TRUE),
    n_nonevents = sum(y == 0, na.rm = TRUE),
    event_fraction = mean(y == 1, na.rm = TRUE)
  )
}

# rare_event_summary(data, "outcome")

3. Rare-Events Design Checklist

Before fitting any model, document the following.

3.1 Data structure

  • Is the outcome truly rare in the target population, or only in this sample?
  • Are there site, era, or subgroup clusters that imply partial pooling?
  • Are there predictors with near-zero variance in event cases?

3.2 Outcome definition

  • Is the outcome clinically coherent?
  • Could outcome misclassification be more harmful than predictor noise?
  • Is the time window aligned correctly for all observations?

3.3 Modeling choices

  • Is penalization needed?
  • Is a hierarchical structure needed?
  • Is the model intended for prediction, explanation, or screening?

3.4 Evaluation choices

  • Will calibration be reported, not only discrimination?
  • Will precision-recall be shown in addition to AUROC?
  • Will decision thresholds be justified clinically?

4. Baseline Logistic Regression Template

A baseline logistic model is still useful as a reference model.

# Example formula:
# fit_glm <- stats::glm(
#   outcome ~ age + severity + lactate + mechanism,
#   data = data,
#   family = stats::binomial()
# )
#
# summary(fit_glm)

But in rare-event settings, a standard maximum-likelihood logistic model can behave poorly when there is separation or when event counts are thin relative to model complexity (King and Zeng 2001).


5. Penalized Logistic Regression Template

Penalization is often a better default than ordinary logistic regression when the outcome is rare.

5.1 Ridge / lasso template with glmnet

required_pkgs <- c("glmnet")
missing_pkgs <- required_pkgs[
  !vapply(required_pkgs, requireNamespace, logical(1), quietly = TRUE)
]
if (length(missing_pkgs) > 0) {
  stop("Missing packages: ", paste(missing_pkgs, collapse = ", "))
}

x <- stats::model.matrix(outcome ~ age + severity + lactate + mechanism, data = data)[, -1]
y <- data$outcome

cv_fit <- glmnet::cv.glmnet(
  x = x,
  y = y,
  family = "binomial",
  alpha = 0
)

cv_fit$lambda.min

5.2 Firth logistic regression template

Bias-reducing penalization can be especially useful under separation or near-separation (Firth 1993).

required_pkgs <- c("brglm2")
missing_pkgs <- required_pkgs[
  !vapply(required_pkgs, requireNamespace, logical(1), quietly = TRUE)
]
if (length(missing_pkgs) > 0) {
  stop("Missing packages: ", paste(missing_pkgs, collapse = ", "))
}

fit_firth <- brglm2::brglm(
  outcome ~ age + severity + lactate + mechanism,
  data = data,
  family = stats::binomial("logit"),
  type = "AS_mean"
)

summary(fit_firth)

The main point is not that one penalization strategy always wins. It is that rare-event settings usually justify more conservative estimation than naïve maximum likelihood.


6. Prediction Extraction and Basic Performance Objects

make_prediction_frame <- function(y_true, p_hat) {
  tibble::tibble(
    y = as.integer(y_true),
    p_hat = p_hat
  ) |>
    dplyr::mutate(
      pred_class_05 = as.integer(p_hat >= 0.5)
    )
}

# Example:
# pred_df <- make_prediction_frame(data$outcome, stats::predict(fit_glm, type = "response"))

7. Why Accuracy Is Usually Misleading

In rare-outcome settings, a classifier can achieve high accuracy simply by predicting the non-event class almost all the time.

That is why performance summaries should emphasize:

  • calibration
  • sensitivity and positive predictive value at justified thresholds
  • precision-recall behavior
  • decision relevance

not raw accuracy alone (Steyerberg 2019; Harrell 2015).


8. Precision-Recall Metrics and Threshold Tables

threshold_metrics <- function(y, p_hat, thresholds = seq(0.01, 0.50, by = 0.01)) {
  purrr::map_dfr(thresholds, function(th) {
    pred <- as.integer(p_hat >= th)
    tp <- sum(pred == 1 & y == 1, na.rm = TRUE)
    fp <- sum(pred == 1 & y == 0, na.rm = TRUE)
    fn <- sum(pred == 0 & y == 1, na.rm = TRUE)
    tn <- sum(pred == 0 & y == 0, na.rm = TRUE)

    tibble::tibble(
      threshold = th,
      sensitivity = ifelse((tp + fn) == 0, NA_real_, tp / (tp + fn)),
      specificity = ifelse((tn + fp) == 0, NA_real_, tn / (tn + fp)),
      ppv = ifelse((tp + fp) == 0, NA_real_, tp / (tp + fp)),
      npv = ifelse((tn + fn) == 0, NA_real_, tn / (tn + fn))
    )
  })
}

# Example:
# threshold_metrics(pred_df$y, pred_df$p_hat)

In rare-event applications, PPV may remain modest even for useful models, so thresholds should be justified relative to clinical workflow and intervention burden rather than judged abstractly.


9. Calibration Checks

Rare-event models should always include calibration assessment.

A simple logistic recalibration model is:

\[ \text{logit}(P(Y=1)) = \alpha + \beta \cdot \text{logit}(\hat p) \]

where:

  • \(\alpha\) is calibration-in-the-large
  • \(\beta\) is the calibration slope
safe_logit <- function(p, eps = 1e-6) {
  stats::qlogis(pmin(pmax(p, eps), 1 - eps))
}

calibration_slope_intercept <- function(y, p_hat) {
  lp <- safe_logit(p_hat)
  fit <- stats::glm(y ~ lp, family = stats::binomial())
  tibble::tibble(
    intercept = unname(stats::coef(fit)[1]),
    slope = unname(stats::coef(fit)[2])
  )
}

# Example:
# calibration_slope_intercept(pred_df$y, pred_df$p_hat)

This matters because rare-event models often look acceptable on ranking metrics while still overstating or understating absolute risk (Steyerberg 2019; Van Calster et al. 2019).


10. Reviewer-Facing Reporting Language

Use language like this in a manuscript or technical appendix:

Because the outcome was rare, we treated model development and evaluation as a rare-events workflow rather than relying on standard logistic regression summaries alone. We emphasized calibration, threshold-specific performance, and penalized estimation where appropriate. Accuracy was not used as a primary metric because it can be dominated by the majority class in low-event settings (King and Zeng 2001; Steyerberg 2019).


11. Minimum Reporting Checklist

  • outcome prevalence reported clearly
  • candidate predictor count justified relative to signal
  • modeling strategy documented
  • penalization strategy documented if used
  • calibration reported
  • threshold-specific operating characteristics reported
  • uncertainty reported
  • intended use case stated explicitly

NoteWhere This Shows Up in AI/ML

Massive transfusion prediction, traumatic arrest survival, and penetrating cardiac injury outcome models are all rare-event problems where the standard ML training loop fails — gradient descent on imbalanced data produces models that learn to predict the majority class and ignore the clinically important minority. Threshold-moving, cost-sensitive learning, and post-hoc calibration with isotonic regression are the three tools that separate a publishable rare-event model from a deployable one; most published trauma AI models demonstrate the first but skip the latter two. In DoDTR-based analyses, the rarest outcomes are often the highest-stakes ones: a model that never predicts massive transfusion is technically achieving 95% accuracy while being clinically useless. Reporting only AUC on an imbalanced DoDTR cohort without specifying the class prevalence and threshold strategy is one of the most common methodological failures in military health AI.

12. Closing

Rare outcomes do not merely make models harder to estimate. They change what responsible modeling looks like.

A defensible rare-events workflow should be more conservative about estimation, more explicit about calibration, and more honest about threshold tradeoffs than an ordinary binary-outcome workflow.

Series Callout

Note

This post is part of a broader Toolkit Series for Applied Statistics, AI, and Clinical Analytics:

  • Bayesian Workflow Toolkit
  • Calibration Toolkit
  • Missing Data Toolkit
  • Rare Events Toolkit
  • Causal Inference Toolkit
  • Survival Analysis Toolkit
  • Prediction Modeling Toolkit
  • Real-World Evidence Toolkit
  • OMOP and Interoperability Toolkit
  • Trauma Registry Analytics Toolkit

References

Firth, David. 1993. “Bias Reduction of Maximum Likelihood Estimates.” Biometrika 80 (1): 27–38. https://doi.org/10.1093/biomet/80.1.27.
Harrell, Jr., Frank E. 2015. Regression Modeling Strategies. 2nd ed. Springer.
King, Gary, and Langche Zeng. 2001. “Logistic Regression in Rare Events Data.” Political Analysis 9 (2): 137–63. https://doi.org/10.1093/oxfordjournals.pan.a004868.
Steyerberg, Ewout W. 2019. Clinical Prediction Models: A Practical Approach to Development, Validation, and Updating. 2nd ed. Springer.
Van Calster, Ben, David J. McLernon, Maarten van Smeden, Laure Wynants, and Ewout W. Steyerberg. 2019. “Calibration: The Achilles Heel of Predictive Analytics.” BMC Medicine 17 (1): 230. https://doi.org/10.1186/s12916-019-1466-7.