cleverly.plotting.sensitivity#

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

Plot one estimate across a declared sensitivity parameter.

Use it to see whether the conclusion changes as a number the analyst chose changes: the probability limits that cap extreme weights, the strength of hidden confounding gamma in the marginal sensitivity model, or the departure gamma from outcomes missing at random. Each value is drawn at its grid point with its interval where the analysis reports one; a grey dashed line marks no effect, and the fitted or main-analysis value is marked.

Parameters:
objTruncationCurve, MarginalSensitivityBounds or MissingnessTilt

The analysis to draw.

**kwargs

estimand= (truncation and missingness), outcome_label=, units=, ax= (bounds and missingness), and the formatting keywords title=, subtitle=, xlabel=, ylabel=, legend= and figsize=, as forest() describes them.

Returns:
Figure

The figure drawn on.

Raises:
TypeError

When obj is not one of the three analyses.

See also

cleverly.plotting.forest

The estimates of a fit with their intervals.

cleverly.assessment.TruncationCurve.plot

This plot for a truncation curve.

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 name the estimands not drawn, say when no validation study licenses an interval (read it as descriptive), and give the sign convention of the sensitivity parameter.

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 sensitivity
>>> 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,
... )
>>> fig = sensitivity(result.diagnostics.truncation_curve())
>>> fig.axes[1].get_ylabel()
'Units capped (%)'
>>> plt.close(fig)