capre: Causal Price-Elastic Recourse for Clinical and Tabular Risk Models
capre (Causal Price-Elastic Recourse) generates actionable, budget-feasible counterfactual recourse plans by combining:
- DAG & Partial-Knowledge Tier Gating (
DAGSpec, DAGSpec.from_tiers): Excludes non-ancestor diagnostic proxies (such as 48-hour laboratory draw counts and missingness indicators) without requiring a complete clinical DAG (supporting sink-only exclusions or coarse (baseline, levers, mediators, sinks) tiers), while flagging confounded_ancestors sharing unmeasured backdoor paths with the outcome.
- Abduct-Act-Predict Propagation & Interventional Causal Shapley (
LinearStructuralModel): Propagates upstream interventions through ridge or cubic-spline structural mediator equations and ranks candidate levers by marginal-residual Interventional Causal Shapley efficiency.
- Microeconomic Disutility & Effort-Isometric Surface Warping (
LeverSpec, PriceTable): Models shared domain initiation costs (economies of scope), directional convex marginal effort, Incremental Cost-Effectiveness Ratios (icer), Net Clinical Benefit (net_benefit), and effort-isometric coordinate maps z = Psi_x(x') (PriceTable.elastic_warp_vector), while selecting diverse candidate bundles across clinical domains and lever sets.
SuperLearner Stacking & Model-Dependence Bounds (CapreSuperLearner, MahalanobisOverlapIndex): Pairs cross-validated log-loss ensemble predictions with inter-learner dispersion sigma_MD(x') (supporting conservative gating p_SL(x') + lambda_MD * sigma_MD(x') <= tau*) and Kish Effective Sample Size (overlap_ess) counterfactual support diagnostics.
Installation
pip install capre
Quick Example
from capre import CapreExplainer, CapreSuperLearner, make_icu_hapri_demo
demo = make_icu_hapri_demo(n=1000, seed=42)
sl_anc = CapreSuperLearner(feature_columns=demo.ancestor_columns, seed=42).fit(
demo.df, demo.df[demo.outcome]
)
tau = sl_anc.oof_youden_threshold()
explainer = CapreExplainer.from_superlearner(
causal_superlearner=sl_anc,
train_df=demo.df,
feature_columns=demo.feature_columns,
outcome=demo.outcome,
price_table=demo.price_table,
dag=demo.dag,
)
high_risk_row = demo.df.loc[sl_anc.predict_risk(demo.df) > tau + 0.15].iloc[0]
result = explainer.explain(high_risk_row, threshold=tau, budget=5.0, lambda_md=0.5)
print(result.to_json())
Vignettes and Interactive Companion