Examples

Examples in Python and R.

Estimate a mean, compare calibration methods, inspect calibration, or estimate a treatment effect.

Examples

Start with your analysis

Each example includes the function call and a link to the full guide.

Example 1

Small labeled sample, large unlabeled sample

Standard semisupervised mean setting: observed outcomes on a small labeled sample, predictions on labeled and unlabeled rows, and one mean to estimate.

Main call: mean_inference(...)

Python

mean_inference(Y, Yhat, Yhat_unlabeled, ...)

R

mean_inference(Y, Yhat, Yhat_unlabeled, ...)

Example 2

Automatic method selection

Compare candidate methods by cross-validated variance estimates, then refit the selected method on all labeled observations.

Main call: method="auto"

Python

mean_inference(..., method="auto")

R

mean_inference(..., method = "auto")

Example 3

Out-of-fold calibration diagnostics

For inspecting the raw prediction scale, making a plot, or checking whether post-hoc calibration is warranted. If only automatic method selection is needed, use method="auto" instead.

Main call: calibration_diagnostics(...)

Python

calibration_diagnostics(...)
plot_calibration(...)

R

calibration_diagnostics(...)
plot(...)

Example 4

Predicted potential outcomes and ATEs

Use predicted potential outcomes to estimate the mean for each treatment arm and each treatment effect relative to control.

Main call: causal_inference(...)

Python

causal_inference(Y, A, Yhat_potential, ...)

R

causal_inference(Y, A, Yhat_potential, ...)

Case Studies

Benchmark results

One case where calibration helps and one where raw AIPW is already sufficient.

Smooth monotone calibration remains the default because it performed well under strong miscalibration in simulations and stayed competitive on the real benchmarks. The figures below are reproducible from the public diagnostics API.

Benchmark: census_income · representative split at n = 1000

Income prediction

Setup. Small labeled sample, much larger unlabeled sample, and a raw prediction score available for everyone.

Results. AIPW and PPI are nearly identical because the unlabeled sample dominates the plug-in term. Simple calibration, especially linear calibration, gives modest gains, and Auto stays competitive.

Representative census_income comparison plot showing smooth calibration curves for the raw AIPW score, the PPI-implied rescaled score, linear calibration, and smooth monotone calibration.
AIPW uses the raw prediction score. PPI uses the implied rescaled score. Linear and smooth monotone calibration move the model output closer to the observed outcome scale.

Benchmark: forest · representative split at n = 500

Strong original score

Setup. The original prediction score is already strong, so calibration has less room to help.

Results. AIPW is already hard to beat, PPI does not offer an advantage, and more flexible calibration gives similar results. At this labeled sample size, the PPI-implied score is visibly over-scaled relative to the outcome level.

Representative forest comparison plot at n equals 500 showing smooth calibration curves for the raw AIPW score, the PPI-implied rescaled score, linear calibration, and smooth monotone calibration.
At n = 500, raw AIPW is already close to the outcome scale. The PPI-style rescaling overshoots, while the calibrated predictions remain closer to the outcome scale.