Cross-calibration
When to use it
Use fit_cross_calibrator() when your treatment-effect model was trained with cross-fitting. Fit the calibration map using pooled out-of-fold predictions, then apply it to predictions from every fold-specific model. This uses the full sample without a separate calibration split.
For each fold, train the treatment-effect model without that fold’s observations. Save its predictions for all observations, not only its held-out fold.
Prepare the inputs
| Input | Shape | Use |
|---|---|---|
predictions |
Length n |
One out-of-fold prediction per observation, used to fit the map |
fold_predictions |
n × K |
Column k contains predictions from the model trained without fold k |
fold_ids |
Length n, optional |
Indices 1 through K identifying the held-out fold for each observation |
| Treatment, outcome, and nuisance estimates | Length n each |
Inputs required by the chosen loss |
Supply fold_ids to check that each pooled prediction equals the entry in its designated column of fold_predictions.
Fit and predict
from causal_calibration import fit_cross_calibrator, validate_crossfit_bundle
validate_crossfit_bundle(
predictions=tau_oof,
fold_predictions=tau_fold_matrix,
fold_ids=fold_ids,
)
cross_calibrator = fit_cross_calibrator(
predictions=tau_oof,
fold_predictions=tau_fold_matrix,
fold_ids=fold_ids,
treatment=a,
outcome=y,
mu0=mu0_hat,
mu1=mu1_hat,
propensity=e_hat,
loss="dr",
method="isotonic",
)
tau_cross_calibrated = cross_calibrator.predict(tau_fold_matrix)library(causalCalibration)
validate_crossfit_bundle(
predictions = tau_oof,
fold_predictions = tau_fold_matrix,
fold_ids = fold_ids
)
cross_calibrator <- fit_cross_calibrator(
predictions = tau_oof,
fold_predictions = tau_fold_matrix,
fold_ids = fold_ids,
treatment = a,
outcome = y,
mu0 = mu0_hat,
mu1 = mu1_hat,
propensity = e_hat,
loss = "dr",
method = "isotonic"
)
tau_cross_calibrated <- predict(cross_calibrator, tau_fold_matrix)Combine predictions
The package fits one map on the pooled out-of-fold scores, applies it to each column of fold_predictions, and takes the median in each row. For an even number of columns, it uses the lower of the two middle values.
For predictions on the training observations, supply the original n × K matrix. For a new sample of size m, apply each fold-specific treatment-effect model to the new observations and supply the resulting m × K matrix, keeping the same column order.
Common mistakes
- Using fitted in-sample scores in
predictionsinstead of out-of-fold scores. - Passing a vector to
predict()instead of the full matrix of fold-specific predictions. - Changing the column order between fitting and prediction.
- Omitting
fold_idswhen you want the package to check out-of-fold alignment.
Full examples
See Diagnostics to assess the calibrated predictions, or the API reference for argument requirements.