metacausal.aggregation.BootstrapResult¶
- class metacausal.aggregation.BootstrapResult(ate, ate_ci_lower, ate_ci_upper, boot_ates, cate, cate_ci_lower, cate_ci_upper, boot_cates=None, component_boot_ates=<factory>, component_ate_estimates=<factory>, component_cate_estimates=None, n_boot=0, n_failed=0, alpha=0.05, aggregation='', ensemble_weights=None, method='nonparametric', subsample_m=None, n_train=0)[source]¶
Bases:
objectBootstrap inference results for both ATE and CATE.
Point estimates (ate, cate) come from the original fit(), not from averaging bootstrap replicates — consistent with standard bootstrap CI practice.
- Variables:
ate (float) – Point estimate from the original fit.
ate_ci_lower (float) – Lower bound of bootstrap CI for ATE.
ate_ci_upper (float) – Upper bound of bootstrap CI for ATE.
boot_ates (np.ndarray) – Bootstrap distribution of ensemble ATEs, shape (B,).
cate (np.ndarray | None) – Point estimate from the original fit, shape (n,). None if no CATE-capable adapters are available.
cate_ci_lower (np.ndarray | None) – Pointwise lower CI bounds, shape (n,). None if no CATE-capable adapters.
cate_ci_upper (np.ndarray | None) – Pointwise upper CI bounds, shape (n,). None if no CATE-capable adapters.
boot_cates (np.ndarray | None) – Bootstrap CATE distributions, shape (B, n). None if no CATE-capable adapters.
component_boot_ates (dict[str, np.ndarray]) – Per-component ATE distributions, {adapter_name: shape (B,)}. Bootstrap samples, not point estimates — contrast with
component_ate_estimates.component_ate_estimates (dict[str, 'ComponentAteEstimate']) – Full-sample per-component ATE point estimates, {adapter_name: ComponentAteEstimate}. Carries the point ATE plus any native CI the method provides (e.g., EconML analytical CIs). Computed during the original fit(); distinct from the bootstrap distributions in
component_boot_ates.component_cate_estimates (dict[str, 'ComponentCateEstimate'] | None) – Full-sample per-component CATE point estimates, {adapter_name: ComponentCateEstimate}. None if no CATE-capable adapter is available. Each entry carries the point CATE array and any native per-grid-point CI.
n_boot (int) – Number of bootstrap replicates requested.
n_failed (int) – Number of replicates that failed entirely.
alpha (float) – Significance level used for CIs.
aggregation (str) – Strategy class name that produced these results.
ensemble_weights (EnsembleWeights | None) – Weights from the original fit (None for pointwise strategies).
method (str) – Bootstrap resampling scheme —
"nonparametric"(n-out-of-n with replacement, the standard Efron bootstrap) or"subsample"(m-out-of-n without replacement, T-stratified; CIs use the Politis–Romano scaled-percentile correction).subsample_m (int | None) – Subsample size used when
method="subsample";Nonefor nonparametric.n_train (int) – Original training sample size. Recorded so
scaleandci_at()can reconstruct the Politis-Romano scale factor after the fact, without needingnpassed back in.
- Parameters:
ate (float)
ate_ci_lower (float)
ate_ci_upper (float)
boot_ates (np.ndarray)
cate (np.ndarray | None)
cate_ci_lower (np.ndarray | None)
cate_ci_upper (np.ndarray | None)
boot_cates (np.ndarray | None)
component_cate_estimates (dict[str, 'ComponentCateEstimate'] | None)
n_boot (int)
n_failed (int)
alpha (float)
aggregation (str)
ensemble_weights (EnsembleWeights | None)
method (str)
subsample_m (int | None)
n_train (int)
Methods
__init__Ensemble CATE along one covariate, with bootstrap CI band.
Confidence interval at an arbitrary level, reusing this bootstrap run's already-computed replicate distribution(s) -- no re-fit needed.
Tabular summary of per-component bootstrap ATE statistics.
Forest plot of per-component and ensemble ATEs.
Return a formatted, multi-line bootstrap summary.
Attributes
sqrt(subsample_m / n_train)formethod="subsample",1.0otherwise (including whenn_trainwasn't recorded, e.g. a hand-builtBootstrapResult).Details
- cate_profile(x, *, xlabel, ax=None, show_components=True, ylim=None, ensemble_label='Ensemble CATE')[source]¶
Ensemble CATE along one covariate, with bootstrap CI band.
Thin wrapper around
metacausal.plots.cate_profile(); see there for the full parameter reference. Requires theplotsextra (pip install 'metacausal[plots]').
- ci_at(level=None, *, dist=None, point_estimate=None)[source]¶
Confidence interval at an arbitrary level, reusing this bootstrap run’s already-computed replicate distribution(s) – no re-fit needed.
By default, reproduces the ensemble’s own ATE CI (at
levelinstead of the level fixed whenbootstrap()was called), using the same Politis-Romano scaled-percentile formula (with themethod="subsample"scale correction applied automatically viascale).Pass
distto get a CI for any other 1-d bootstrap distribution carried by this result – e.g.component_boot_ates["BCF"]for a per-component CI – or one you’ve derived yourself (e.g. a per-replicate mean across components, for an aggregation strategy the ensemble was never actually fit with).distandpoint_estimatemust be overridden together: a bootstrap distribution can only be centered correctly on the point estimate of the same statistic it resamples, and there is no way to infer the right point estimate for an arbitrary distribution.- Parameters:
level (float | None) – Coverage level, e.g.
0.90for a 90% CI. Defaults to1 - self.alpha(the level this result was already constructed at).dist (ndarray | None) – Bootstrap replicate distribution, shape
(B,). Defaults toself.boot_ates.point_estimate (float | None) – Center of the interval. Defaults to
self.ate. Required (and only meaningful) together withdist.
- Returns:
(ci_lower, ci_upper)tuple.- Raises:
ValueError – If exactly one of
dist/point_estimateis given.- Return type:
- component_ate_summary()[source]¶
Tabular summary of per-component bootstrap ATE statistics.
Returns a DataFrame with one row per component adapter, in the insertion order of
component_boot_ates. Each row reports the bootstrap-mean ATE and the1 - alphaCI, viaci_at()(matching the CI convention used by the ensemble itself, including themethod="subsample"scale correction).- Returns:
pandas.DataFrame – Columns:
name: adapter name.mean: bootstrap-mean ATE.lo: lower CI bound.hi: upper CI bound.
- Raises:
ValueError – If
component_boot_atesis empty (bootstrap not run or no component distributions recorded).- Return type:
- forest(*, ax=None, order='value', ensemble_label='Ensemble', show_zero=True)[source]¶
Forest plot of per-component and ensemble ATEs.
Thin wrapper around
metacausal.plots.forest(); see there for the full parameter reference. Requires theplotsextra (pip install 'metacausal[plots]').
- boot_ates: np.ndarray¶
- ensemble_weights: EnsembleWeights | None = None¶