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
SensitivityContourit 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 aSimulatedConfoundingResultit 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:
- obj
SensitivityContourorSimulatedConfoundingResult The analysis to draw.
- **kwargs
For a contour:
robustness=,benchmarks=,multiples=,null=andax=. For a surface:at=,null=andax=. Both take the formatting keywordstitle=,subtitle=,xlabel=,ylabel=,legend=andfigsize=, asforest()describes them.xlabel=andylabel=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.
- obj
- Returns:
FigureThe figure drawn on.
- Raises:
TypeErrorWhen
objis neither analysis.
See also
cleverly.plotting.sensitivityEstimates across a declared sensitivity parameter.
cleverly.sensitivity.contour_dataBuild the grid of bias-adjusted bounds.
cleverly.sensitivity.simulated_confoundingBuild 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)