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:
- result
TMLEResult A fitted
TMLE,DRTMLEorCTMLEresult with a Gaussian or binary outcome. It may have more than two arms, sampling weights, baseline strata or missing outcomes.- gamma
floator sequenceoffloat, 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
CTMLEfit that estimate reads the refitted mechanism, so it is not the C-TMLE estimate.- estimand
strorNone, 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.Nonebounds 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) raisesValueErrornaming the choices.- level
float, default=0.95 The coverage level of the set interval.
- quantile_learner
callable(),optional A factory
tau -> regressorfor the conditionaltau-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_learner
regressor,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_learnerreturns, take the cross-fitting draw’s seed (0 when the draw has none, as the default candidates take) for everyrandom_statethey leave unset.
- result
- Returns:
MarginalSensitivityBoundsOne row per \(\Gamma\).
- Raises:
CapabilityErrorWhen
marginal_bound_refusal()refuses the fit, whenattoratcis 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.ValueErrorWhen
gammaholds a value below 1, orestimandorlevelis invalid.
See also
cleverly.sensitivity.omitted_variable_boundsThe partial-\(R^2\) scale bound.
cleverly.sensitivity.evalueThe 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