Skip to main content

Standard calibration

When to use it

Use fit_calibrator() to fit a single calibration map from one prediction per observation. Fit it on a calibration sample that was not used to train the treatment-effect model.

If your model was trained with cross-fitting and you have predictions from each fold-specific model, use cross-calibration to avoid setting aside a separate calibration sample.

Fit and predict

from causal_calibration import fit_calibrator

calibrator = fit_calibrator(
    predictions=tau_hat,
    treatment=a,
    outcome=y,
    mu0=mu0_hat,
    mu1=mu1_hat,
    propensity=e_hat,
    loss="dr",
    method="isotonic",
)

tau_calibrated = calibrator.predict(tau_hat_new)
library(causalCalibration)

calibrator <- fit_calibrator(
  predictions = tau_hat,
  treatment = a,
  outcome = y,
  mu0 = mu0_hat,
  mu1 = mu1_hat,
  propensity = e_hat,
  loss = "dr",
  method = "isotonic"
)

tau_calibrated <- predict(calibrator, tau_hat_new)

The fitting inputs refer to the calibration sample. tau_hat_new contains predictions from the same treatment-effect model on new observations.

Check the result

Inspect the fitted map and compare raw and calibrated scores. Use diagnose_calibration() to estimate calibration error and its confidence interval on evaluation observations; supply the raw scores as comparison_predictions.

Use assess_overlap() to inspect propensity-score tails and effective sample sizes. If overlap is weak, consider whether calibration for an overlap-weighted population would answer your scientific question before changing to loss="r".

See also