metacausal.plots.cate_profile

metacausal.plots.cate_profile(source, x, *, xlabel, ax=None, show_components=True, ylim=None, ensemble_label='Ensemble CATE')[source]

Ensemble CATE along one covariate, with optional bootstrap CI.

The x-axis is the varied covariate; the y-axis is CATE. Individual component CATEs are optionally overlaid in grey. A shaded 1 - alpha pointwise CI is drawn only when a BootstrapResult is supplied.

Parameters:
  • source (BootstrapResult | CateEstimate) –

    Either:

    • A BootstrapResult produced by CausalEnsemble.bootstrap(X_grid, ...) — draws the CI band plus ensemble and component lines. Must have a non-None cate.

    • A CateEstimate produced by CausalEnsemble.cate(X_grid) — draws ensemble and component lines only, no band.

    The grid length must match len(x).

  • x (np.ndarray) – Values of the varied covariate, shape (grid_size,). These become the x-axis coordinates.

  • xlabel (str) – Axis label for x (e.g., "re74 (1974 earnings)").

  • ax (Axes | None) – Existing axes to draw on. If None, a new figure is created.

  • show_components (bool) – If True, overlay per-component CATEs as thin grey lines. Only drawn when source carries component estimates.

  • ylim (tuple[float, float] | None) – Optional y-axis limits. Useful when a single component has extreme CATE values that compress the ensemble signal.

  • ensemble_label (str) – Legend label for the ensemble line.

Returns:

Axes – The axes the plot was drawn on.

Raises:

ValueError – If source carries no CATE data (e.g., a BootstrapResult whose cate is None), or if len(x) does not match the grid length on source.

Return type:

Axes

Examples

Works directly on a standalone CateEstimate (as returned by CausalEnsemble.cate(X_grid)), constructed by hand here with a toy grid and a single component:

>>> import numpy as np
>>> from metacausal.estimators import CateEstimate, ComponentCateEstimate
>>> from metacausal.plots import cate_profile
>>> x = np.linspace(0, 1, 5)
>>> result = CateEstimate(
...     cate=x * 2,
...     component_estimates={"a": ComponentCateEstimate(cate=x * 2 + 0.1)},
...     aggregation="Median",
... )
>>> ax = cate_profile(result, x, xlabel="x")
>>> ax.get_ylabel()
'CATE'

(Source code, png)

../_images/metacausal-plots-cate_profile-1.png