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:
- obj
TruncationCurve,MarginalSensitivityBoundsorMissingnessTilt The analysis to draw.
- **kwargs
estimand=(truncation and missingness),outcome_label=,units=,ax=(bounds and missingness), and the formatting keywordstitle=,subtitle=,xlabel=,ylabel=,legend=andfigsize=, asforest()describes them.
- obj
- Returns:
FigureThe figure drawn on.
- Raises:
TypeErrorWhen
objis not one of the three analyses.
See also
cleverly.plotting.forestThe estimates of a fit with their intervals.
cleverly.assessment.TruncationCurve.plotThis 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)