cleverly.sensitivity.SensitivityContour#
- class cleverly.sensitivity.SensitivityContour(rows: tuple[tuple[str, tuple[Any, ...]], ...], backend: str | None, estimand: str = '', psi: float = nan, bound: str = 'lower', rho: float = 1.0, scale: str = 'level', max_bias: float = nan, nu2: float = nan, nu2_estimator: str = 'doubly_robust', n_repeats: int = 1, assumption: str | None = None)[source]#
One end of the bias-adjusted range over a grid of confounder strengths.
Returned by
contour_data().to_frame()gives the long frame ofcf_d,cf_yandvaluefor a contour plot.- Parameters:
- rows
tuple The
cf_d,cf_yandvaluecolumns, as(name, values)pairs.- backend
strorNone The dataframe backend
to_frame()emits.- estimand
str The estimand the grid bounds.
- psi
float Its reported estimate.
- bound{“lower”, “upper”}
Which end of the range each cell holds.
- rho
float The alignment every cell assumes.
- scale{“difference”, “level”}
The scale of the estimate, as the fit reports it. A difference has a no-effect value of zero, and a level (a counterfactual mean) has none.
- max_bias
float The bias scale
sqrt(sigma^2 nu^2)every cell multiplies, the median over the fit’s draws.- nu2
float The Riesz second moment
nu^2behind it, the median over the fit’s draws.- nu2_estimator{“doubly_robust”, “plugin”}
The estimator of
nu^2the cells use.- n_repeats
int The fit’s cross-fitting draws. Each cell is the median over them.
- assumption
strorNone The sentence a point bound under
assume_consistent_mechanism=Truecarries, elseNone.
- rows
Methods#
- classmethod SensitivityContour.build(payload: Mapping[str, Sequence[Any]], *, backend: str | None, estimand: str, psi: float, bound: str, rho: float, scale: str, max_bias: float, nu2: float, nu2_estimator: str, n_repeats: int, assumption: str | None) SensitivityContour[source]#
Build the grid from its columns.
- Parameters:
- payload
mappingofstrtosequence The
cf_d,cf_yandvaluecolumns.- backend
strorNone The backend
to_frame()emits.- estimand
str The estimand the grid bounds.
- psi
float Its reported estimate.
- bound{“lower”, “upper”}
Which end of the range each cell holds.
- rho
float The alignment every cell assumes.
- scale
str The scale of the estimate.
- max_bias
float The bias scale every cell multiplies.
- nu2
float The Riesz second moment behind it.
- nu2_estimator
str The estimator of
nu^2.- n_repeats
int The fit’s cross-fitting draws.
- assumption
strorNone The consistent-mechanism sentence, or
None.
- payload
- Returns:
SensitivityContourThe grid.
- SensitivityContour.plot(**kwargs: Any) Any[source]#
Plot the bias-adjusted bound over the two confounder strengths.
- Parameters:
- **kwargs
Passed to
cleverly.plotting.confounding():robustness=,benchmarks=,multiples=,null=,ax=and the formatting keywordstitle=,subtitle=,xlabel=,ylabel=,legend=andfigsize=.
- Returns:
FigureA filled contour of the cells with the no-effect contour in bold.
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.sensitivity import contour_data, robustness_value >>> frame, _ = make_linear_ate(n=200, seed=0) >>> design = PointTreatment( ... outcome="Y", treatment="A", adjustment=("W1", "W2", "W3", "W4") ... ) >>> result = CausalStudy(frame, design=design).identify(ATE()).estimate( ... outcome_learner=LinearRegression(), ... treatment_learner=LogisticRegression(max_iter=1000), ... cross_fit=False, ... random_state=0, ... ) >>> contour = contour_data(result, "ate", grid_size=8) >>> fig = contour.plot(robustness=robustness_value(result, "ate")) >>> fig.axes[-1].get_ylabel() 'Bias-adjusted lower bound, no sampling error' >>> plt.close(fig)