cleverly.plotting.confounding#

cleverly.plotting.confounding(obj: Any, **kwargs: Any) → Figure[source]#

Plot how strong hidden confounding would need to be, or how far a simulated one moves us.

Use it to read a sensitivity analysis to confounding that was not measured. For a SensitivityContour it maps the bias-adjusted bound of the estimate over the two strengths of left-out variables, with the contour where the bound reaches the null in bold, the point robustness value on the diagonal and benchmark covariates marked at their gains. For a SimulatedConfoundingResult it maps the refitted estimate over the declared strengths of a simulated common cause, in the units of its own perturbation laws, and says it is qualitative.

Parameters:
objSensitivityContour or SimulatedConfoundingResult

The analysis to draw.

**kwargs

For a contour: robustness=, benchmarks=, multiples=, null= and ax=. For a surface: at=, null= and ax=. Both take the formatting keywords title=, subtitle=, xlabel=, ylabel=, legend= and figsize=, as forest() describes them. xlabel= and ylabel= replace the words on the two strength axes, such as "Weight side" and "Score side" for a page that names the two strengths that way.

Returns:
Figure

The figure drawn on.

Raises:
TypeError

When obj is neither analysis.

See also

cleverly.plotting.sensitivity

Estimates across a declared sensitivity parameter.

cleverly.sensitivity.contour_data

Build the grid of bias-adjusted bounds.

cleverly.sensitivity.simulated_confounding

Build the simulated-confounding surface.

Notes

The figure carries no note text. It does not mark an experimental fit or band, one whose interval has no checked coverage because no registered study covers it or a stated condition applies, such as too few clusters: read notes() on the figure before you publish it. For this plot the notes define the two strengths, list benchmarks or calibrations that are not marked and why, and say that a simulated-confounding map is qualitative: not a bound or an interval.

Examples

>>> import matplotlib
>>> matplotlib.use("Agg")
>>> import matplotlib.pyplot as plt
>>> from sklearn.linear_model import LinearRegression, LogisticRegression
>>> from cleverly import ATE, CausalStudy, PointTreatment
>>> from cleverly.datasets import make_linear_ate
>>> from cleverly.plotting import confounding
>>> from cleverly.sensitivity import contour_data, robustness_value
>>> frame, _ = make_linear_ate(n=200, seed=0)
>>> study = CausalStudy(
...     frame,
...     design=PointTreatment(outcome="Y", treatment="A", adjustment=("W1", "W2", "W3", "W4")),
... )
>>> result = study.identify(ATE()).estimate(
...     outcome_learner=LinearRegression(),
...     treatment_learner=LogisticRegression(max_iter=1000),
...     cross_fit=False,
...     random_state=0,
... )
>>> grid = contour_data(result, "ate", grid_size=8)
>>> fig = confounding(grid, robustness=robustness_value(result, "ate"))
>>> fig.axes[0].get_title(loc="left")
'Sensitivity to hidden confounding'
>>> plt.close(fig)