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:
rowstuple of MarginalSensitivityRow

One row per \(\Gamma\), in increasing order.

estimandstr

The bounded parameter.

levelfloat

The coverage level of the set interval.

nullfloat or None

The null value of the estimand: 0.0 for a difference, 1.0 for a ratio and None for an arm mean.

outcome_kind{“continuous”, “binary”}

Which nuisance route the bounds used.

quantile_learnertuple of str

The quantile learner each side and arm selected, or () for a binary outcome.

pseudo_outcome_learnertuple of str

The tail-regression learner each side and arm selected, or ().

limit_readingResolution or None

The registry’s reading of the confidence limits.

backendstr or None

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_dfint or None

The degrees of freedom of the Student t reference of the limits, the fit’s own rule over the rows the bounded parameter reads; None for the normal reference.

Attributes:
breakdownfloat or None

The smallest grid \(\Gamma\) whose point bounds contain the null.

limit_breakdownfloat or None

The smallest grid \(\Gamma\) whose set interval contains the null.

limit_descriptivebool

Whether 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= and title=.

Returns:
Figure

One 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:
Summary

A str that 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:
DataFrame

The fields of MarginalSensitivityRow.

Attributes#

MarginalSensitivityBounds.backend: str | None = None#
MarginalSensitivityBounds.breakdown#

The smallest grid \(\Gamma\) whose point bounds contain the null.

None for 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.limit_reading: Resolution | None = None#
MarginalSensitivityBounds.pseudo_outcome_learner: tuple[str, ...] = ()#
MarginalSensitivityBounds.quantile_learner: tuple[str, ...] = ()#
MarginalSensitivityBounds.reference_df: int | None = None#
MarginalSensitivityBounds.scale: str = 'identity'#
MarginalSensitivityBounds.rows: tuple[MarginalSensitivityRow, ...]#
MarginalSensitivityBounds.estimand: str#
MarginalSensitivityBounds.level: float#
MarginalSensitivityBounds.null: float | None#
MarginalSensitivityBounds.outcome_kind: str#