PyPI install
python -m pip install ppi-aipw
Package overview
Estimate a population mean using a small labeled sample and
predictions on a larger unlabeled sample. ppi_aipw
calibrates the predictions on the labeled outcomes, then computes
an AIPW estimate with a standard error and confidence interval.
Use predictions from an existing model; no retraining is needed.
Install
Use PyPI for the release, GitHub for the current source, or an editable install for local development. The native R package has a separate R page.
python -m pip install ppi-aipw
python -m pip install "git+https://github.com/Larsvanderlaan/ppi-aipw.git"
python -m pip install -e .
Quickstart
Pass the outcomes and predictions to mean_inference(...).
The result includes the estimate, standard error, confidence
interval, fitted calibrator, and diagnostics.
For a runnable example, the quickstart notebook opens directly in Colab and covers both the mean and causal APIs.
For data-adaptive selection, set method="auto" and
pass candidate_methods=("aipw", "linear", "monotone_spline", "isotonic").
Selection uses num_folds=100 by default, capped at
the labeled sample size.
Use result.summary() for estimates, intervals, and p-values.
Use calibration_diagnostics(result, Y, Yhat) for
an optional out-of-fold calibration check.
YObserved outcomes for the labeled sample.
YhatPredictions on the same labeled rows.
Yhat_unlabeledPredictions on the unlabeled sample.
methodChoose "aipw", "linear", "prognostic_linear", "sigmoid", "monotone_spline", "isotonic", or "auto".
cross_fitDefaults to False. Set True to fit calibration, method selection, and efficiency scaling on training folds and evaluate on held-out observations from both samples.
calibration_foldsNumber of honest calibration folds, default 10. Use len(Y) for leave-one-out labeled calibration when the unlabeled sample is larger.
candidate_methodsCandidate methods considered when method="auto" minimizes a cross-validated variance estimate. If "aipw" is included, the selector also compares a rescaled AIPW candidate.
num_foldsNumber of folds used by method="auto". The default is 100 and it is capped at the labeled sample size.
inferenceChoose "wald" for a fast analytic interval, "jackknife" for a V-fold jackknife interval with Student t critical values, or "bootstrap" for percentile bootstrap intervals.
efficiency_maximizationOptional rescaling to lambda m(X). For method="aipw", m(X) is the raw score; otherwise it is the calibrated score.
w, w_unlabeledOptional observation weights for labeled and unlabeled samples. Uniform weights reproduce the unweighted estimator.
X, X_unlabeledOptional extra covariates for method="prognostic_linear". The score and intercept are unpenalized; extra covariates use ridge tuning on the labeled sample.
Calibration
A score can rank outcomes well while predicting values that are too high or too low.
A calibrated score of 0.8 corresponds to an average
outcome of 0.8. Calibration estimates this relationship
from the labeled sample and adjusts the original predictions.
AIPW averages predictions over both samples and adds the average residual from the labeled sample. Calibrating the predictions can reduce the variability of those residuals and improve precision.
Methods
Compare the fitted curves, assumptions, and options below.
Fits a smooth nondecreasing curve to the labeled outcomes, then uses the calibrated predictions in AIPW. This is the default method.
A smooth nondecreasing curve adjusts the score while preserving its ordering. The plot is schematic.
Intervals
Wald intervals use an analytic standard error. Jackknife and
bootstrap intervals refit calibration. Jackknife uses
jackknife_folds=10 and Student t critical values.
Uses an analytic standard error and a normal approximation.
References
The calibration methods here can be viewed as special cases of calibrated debiased machine learning and targeted minimum loss estimation.
The AIPW baseline cited above goes back to Robins, Rotnitzky, and Zhao (1994), "Estimation of regression coefficients when some regressors are not always observed", Journal of the American Statistical Association 89(427): 846-866.
Calibration references:
Semiparametric, debiased/targeted machine learning foundations:
Prognostic-score adjustment and efficiency maximization:
Semisupervised mean estimation: