cleverly.sensitivity.MarginalSensitivityBounds#
- class cleverly.sensitivity.MarginalSensitivityBounds(rows: tuple[MarginalSensitivityRow, ...], estimand: str, level: float, null: float | None, outcome_kind: str, quantile_learner: tuple[str, ...] = (), pseudo_outcome_learner: tuple[str, ...] = (), limit_reading: Resolution | None = None, backend: str | None = None, scale: str = 'identity', reference_df: int | None = None)[source]#
Marginal sensitivity model bounds over a grid of \(\Gamma\).
- Parameters:
- rows
tupleofMarginalSensitivityRow One row per \(\Gamma\), in increasing order.
- estimand
str The bounded parameter.
- level
float The coverage level of the set interval.
- null
floatorNone The null value of the estimand:
0.0for a difference,1.0for a ratio andNonefor an arm mean.- outcome_kind{“continuous”, “binary”}
Which nuisance route the bounds used.
- quantile_learner
tupleofstr The quantile learner each side and arm selected, or
()for a binary outcome.- pseudo_outcome_learner
tupleofstr The tail-regression learner each side and arm selected, or
().- limit_reading
ResolutionorNone The registry’s reading of the confidence limits.
- backend
strorNone The dataframe backend of the fit’s data, which
to_frame()emits.- scale{“identity”, “log”}
The scale of the standard errors. A risk ratio or an odds ratio reports its ends and limits on the ratio scale and its standard errors on the log scale.
- reference_df
intorNone The degrees of freedom of the Student t reference of the limits, the fit’s own rule over the rows the bounded parameter reads;
Nonefor the normal reference.
- rows
- Attributes:
breakdownfloatorNoneThe smallest grid \(\Gamma\) whose point bounds contain the null.
limit_breakdownfloatorNoneThe smallest grid \(\Gamma\) whose set interval contains the null.
limit_descriptiveboolWhether the confidence limits print without a licensed interpretation.
Methods#
- MarginalSensitivityBounds.plot(**kwargs: Any) Any[source]#
Plot the range of the estimate against Γ, with its interval and no-effect line.
- Parameters:
- **kwargs
Passed to
cleverly.plotting.sensitivity():outcome_label=,units=andtitle=.
- Returns:
FigureOne panel over the grid of Γ.
Examples
>>> import matplotlib >>> matplotlib.use("Agg") >>> import matplotlib.pyplot as plt >>> import numpy as np, pandas as pd >>> from sklearn.linear_model import LogisticRegression >>> from cleverly.estimators import TMLE >>> from cleverly.sensitivity import marginal_sensitivity_bounds >>> rng = np.random.default_rng(0) >>> w = rng.normal(size=300) >>> a = rng.binomial(1, 1 / (1 + np.exp(-w))) >>> y = rng.binomial(1, 1 / (1 + np.exp(-(w + a - 0.5)))) >>> frame = pd.DataFrame({"W": w, "A": a, "Y": y}) >>> fit = TMLE( ... outcome_learner=LogisticRegression(), ... treatment_learner=LogisticRegression(), ... random_state=0, ... ).fit(frame, outcome="Y", treatment="A", covariates=["W"]).single() >>> fig = marginal_sensitivity_bounds(fit, gamma=(1.0, 1.5, 2.0, 3.0)).plot() >>> fig.axes[0].get_ylabel() 'Range of the average effect' >>> plt.close(fig)
- MarginalSensitivityBounds.summary(*, detail: Detail = 'short') Summary[source]#
Return the printed summary.
- Parameters:
- detail{“short”, “full”}
"full"adds the assumptions and the settings.
- Returns:
SummaryA
strthat prints the question, the numbers and how to read them, and keeps its header, tables and notes as data.
- MarginalSensitivityBounds.to_frame() Any[source]#
Return one row per \(\Gamma\), in the backend of the fit’s data.
- Returns:
DataFrameThe fields of
MarginalSensitivityRow.
Attributes#
- MarginalSensitivityBounds.breakdown#
The smallest grid \(\Gamma\) whose point bounds contain the null.
Nonefor an arm mean, or when no grid value reaches the null.
- MarginalSensitivityBounds.limit_breakdown#
The smallest grid \(\Gamma\) whose set interval contains the null.
- MarginalSensitivityBounds.limit_descriptive#
Whether the confidence limits print without a licensed interpretation.
- MarginalSensitivityBounds.rows: tuple[MarginalSensitivityRow, ...]#