cleverly.sensitivity.benchmark#
- cleverly.sensitivity.benchmark(result: TMLEResult, covariates: Any, *, estimand: str = 'ate', nu2_estimator: str = 'auto', random_state: int | None = None) BenchmarkResult[source]#
Calibrate
cf_yandcf_dagainst observed covariates.Refits the whole model without the named covariates (the “short” model) and compares it with the full fit. The resulting gain statistics say how strong a confounder like the dropped ones would be, on the
cf_y/cf_dscale, which turns an abstract sensitivity parameter into a concrete comparison.Note this is a genuine refit, so it costs about as much as the original fit.
- Parameters:
- result
TMLEResult A fitted result.
- covariatessequence
ofstr Observed covariates to calibrate against. An encoded categorical covariate is named by its column, and the refit drops its whole block of indicator columns.
- estimand
str Alias to benchmark.
- nu2_estimator{“auto”, “doubly_robust”, “plugin”}
Which estimator of the Riesz second moment to use.
- random_state
intorNone Seed for the short refit.
Noneuses the seed the fit was run with. A fit with no seed draws one. Either way the result records it underrandom_state, and passing that value back repeats the benchmark.
- result
- Returns:
BenchmarkResultThe sensitivity parameters a confounder as important as those covariates would need, and how far the estimate moved without them.
- Raises:
DataErrorIf
covariatesis empty, names an indicator column of an encoded covariate, or names a covariate the fit does not adjust for. The argument is checked before any refusal.ValueErrorIf
nu2_estimatoris not one ofNU2_ESTIMATORS.CapabilityErrorIf the result carries no fitted estimator, on every refusal
sensitivity_elements()raises for the full fit or the short refit, and on the refusal ofbenchmark_refusal. The full fit and the covariates are checked before the refit runs.