API reference
Core fitting functions
fit_calibrator()
Fit a single calibration map on predictions from a separate calibration sample.
Required by loss
loss="dr":mu0,mu1,propensityloss="r":outcome_mean,propensity
Common mistakes
- supplying raw learner objects instead of prediction vectors,
- forgetting
outcome_meanforloss="r", - using non-binary treatment indicators.
fit_cross_calibrator()
Use for cross-fitted treatment-effect predictions.
Prediction inputs
predictions: pooled out-of-fold predictions used to fit the calibration mapfold_predictions:n x Kmatrix used for calibrated aggregation at prediction timefold_ids: optional out-of-fold column index per observation; when supplied, the package checks that each out-of-fold prediction matches the entry in its designated column.
Common mistakes
- swapping
predictionsandfold_predictions, - passing a single-column matrix instead of predictions from all fold-specific models,
- forgetting that prediction later also expects a fold-specific matrix.
Validation helpers
validate_crossfit_bundle(...): validate pooled OOF predictions, fold matrices, and optional fold IDs before fitting.crossfit_bundle(...)/crossfit_bundle_from_data_frame(...): collect predictions, nuisance estimates, and fold information in one object.
diagnose_calibration()
Estimate a calibration curve and squared L2 calibration error, and report confidence intervals and a best linear projection of the pseudo-outcome on the score.
Inputs
predictions,treatment,outcome,mu0,mu1, andpropensity,outcome_meanfor the overlap target (if omitted, computed frommu0,mu1, andpropensity),- optional comparison vector,
- optional
target_population = "dr" | "overlap" | "both".
Interpretation
Select the original or overlap-weighted population with target_population. See Diagnostics for interpretation.
assess_overlap()
Summarize propensity-score tails and effective sample sizes before choosing a calibration loss.
Outputs
- propensity min/max,
- tail fractions below
0.05,0.10, above0.90,0.95used by the default screen, - clipped fraction,
- IPW effective sample size,
- overlap-weight effective sample size,
- severity label and recommended loss under the package defaults.
The severity label and loss recommendation use practical screening cutoffs. Choose the target population based on your scientific question.
Bundle helpers
calibration_bundle(...)/calibration_bundle_from_data_frame(...)crossfit_bundle(...)/crossfit_bundle_from_data_frame(...)fit_bundle_calibrator(...)fit_bundle_cross_calibrator(...)
Fitted objects
Calibrator
predict(...): apply the fitted calibration mapsummary(): fitting options and sample size- plotting: visualize the fitted calibration map
CrossCalibrator
predict(...): apply the map to a fold-specific matrix and aggregate with the order-statistic mediansummary(): metadata summary including fold count
CalibrationDiagnostics
summary(): scalar results, BLP slope/intercept summaries, and intervals- plotting helpers: display the estimated calibration curve
Full examples
- Python notebook: examples/python-workflow.ipynb
- R vignette: r/causalCalibration/vignettes/getting-started.Rmd