cleverly.sensitivity.marginal_sensitivity_bounds#

cleverly.sensitivity.marginal_sensitivity_bounds(result: TMLEResult, gamma: float | Sequence[float] = (1.0, 1.5, 2.0), *, estimand: str | None = None, level: float = 0.95, quantile_learner: QuantileFactory | None = None, pseudo_outcome_learner: Any = None) → MarginalSensitivityBounds[source]#

Bound an arm mean or the ATE under the marginal sensitivity model.

Parameters:
resultTMLEResult

A fitted TMLE, DRTMLE or CTMLE result with a Gaussian or binary outcome. It may have more than two arms, sampling weights, baseline strata or missing outcomes.

gammafloat or sequence of float, default=DEFAULT_GAMMA_GRID

The sensitivity parameter \(\Gamma \ge 1\) (Tan’s \(\Lambda\)), or a grid. \(\Gamma = 1\) reproduces the cross-fitted AIPW estimate. On a selecting CTMLE fit that estimate reads the refitted mechanism, so it is not the C-TMLE estimate.

estimandstr or None, default=None

The reported name of an arm mean ("ey1"), a difference ("ate"), an effect on the treated or the controls ("att", "atc", two arms only), a ratio ("rr", "or"), any of these against a named reference arm, or a stratum-conditional alias such as "ate[V=1]". The fit need not have reported it. None bounds the fit’s own reported parameter: the ATE when the fit reports it, else the one reported parameter the bounds can take. A fit that reports two or more of them and no ATE (or none of them) raises ValueError naming the choices.

levelfloat, default=0.95

The coverage level of the set interval.

quantile_learnercallable(), optional

A factory tau -> regressor for the conditional tau-quantile of a continuous outcome. By default the bounds select, by out-of-fold pinball loss, between a linear quantile regression and a shallow boosted quantile regression.

pseudo_outcome_learnerregressor, optional

The regression of the tail pseudo-outcome. By default the bounds select, by out-of-fold squared loss, between a linear regression and a shallow booster. A declared learner, and the regressor quantile_learner returns, take the cross-fitting draw’s seed (0 when the draw has none, as the default candidates take) for every random_state they leave unset.

Returns:
MarginalSensitivityBounds

One row per \(\Gamma\).

Raises:
CapabilityError

When marginal_bound_refusal() refuses the fit, when att or atc is asked of a fit with more than two arms, or when a ratio’s outcome scale does not fit it or an arm bound has no logarithm.

ValueError

When gamma holds a value below 1, or estimand or level is invalid.

See also

cleverly.sensitivity.omitted_variable_bounds

The partial-\(R^2\) scale bound.

cleverly.sensitivity.evalue

The risk-ratio scale summary.

Examples

>>> import numpy as np, pandas as pd
>>> from sklearn.linear_model import LinearRegression, 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()
>>> bounds = marginal_sensitivity_bounds(fit, gamma=(1.0, 2.0))
>>> row_1, row_2 = bounds.rows
>>> bool(np.isclose(row_1.lower, row_1.upper))
True
>>> bool(row_2.lower < row_1.lower and row_2.upper > row_1.upper)
True