cleverly.AdaptiveTMLEMethod#
- class cleverly.AdaptiveTMLEMethod(models: ModelSpec = ModelSpec(outcome_learner=None, treatment_learner=None, missingness_learner=None, intermediate_learner=None, pseudo_learner=None, censoring_learner=None, competing_learner=None, density_bins=None, ratio='density', screen_treatment=False, screen_threshold=0.1, min_retain=None, hazard_pooling='node', outcome_by_arm=False, survival_model=None), cross_fitting: CrossFitting = CrossFitting(enabled=True, n_folds=5, learner_folds=5, repeats=1, stratify_by='none', targeting_scheme='pooled', fold_evaluation=False, split_plan=None), targeting: Targeting = Targeting(fluctuation='logistic', algorithm='iterative', g_bounds='auto', q_bounds=None, nuisance_bound=0.01, submodel_alpha=0.9995, target_weights=False, step_size=0.001, max_iter=20, tol=1e-10, stopping='relative', step_bound=None, step_search=True, iterate='last', conditional_form='arm_mean', isotonic=False, ratio_trim=None, node_bounds=None), inference: Inference = Inference(alpha=0.05, n_bootstrap=0, bootstrap_resampling='auto', simultaneous=None, n_multiplier=10000, multiplier_kind='mammen', band_scale='logit', band_reference='normal'), runtime: Runtime = Runtime(random_state=None, run_id=None, n_jobs=1), name: str = 'atmle', form: Literal['cv', 'pooled'] = 'cv', working_basis: Any = None, source_learner: Any = None, force_arm: bool = False)[source]#
Configure adaptive TMLE for a randomized trial pooled with external data.
The estimator of van der Laan, Qiu, Tarp and van der Laan (arXiv:2405.07186v2) learns two working models by lasso over a dictionary of covariate functions: one for the treatment effect on the pooled rows, and one for how the external outcomes differ from the trial’s. It then targets the trial’s effect, removing the bias the second model describes. The interval covers the effect within the selected working models, so every estimate carries the status
working_model_projection. OnlyTrialWithExternalDatatakes this method.The method reads the learners of
ModelSpec,enabled,n_folds,learner_foldsandsplit_planofCrossFitting,g_boundsofTargeting,alphaofInferenceandrandom_stateandrun_idofRuntime. Every other field of those groups must keep its default, and a changed one is refused by name with the reason it has no effect.- Parameters:
- models
ModelSpec outcome_learnerfits the outcome regressions,treatment_learnerthe pooled treatment mechanism, andmissingness_learnerthe outcome-observation mechanism.Nonetakes the default Super Learner library.- cross_fitting
CrossFitting, default=CrossFitting(n_folds=5) The outer split, drawn stratified by trial membership (and by the outcome when it is binary) so that each fold holds trial and external rows in proportion.
learner_foldsalso sets the folds of the cross-validation that chooses each lasso penalty.form="cv"needsenabled=Trueand at least three folds.form="pooled"withenabled=Falsefits every nuisance on every row. Asplit_plansupplies the outer folds in place of a drawn split.repeatsabove one is refused.- targeting
Targeting g_boundsbounds the treatment, trial-membership and observation probabilities.- inference
Inference alphasets the interval’s level.- runtime
Runtime Seed and run identifier.
- name
str Stable method name.
- form{“cv”, “pooled”}, default=”cv”
"cv"is the adaptive CV-TMLE (Appendix C, Theorem 2), which selects each fold’s working models on the other folds."pooled"is Algorithm 1 (Section 7, Theorem 1), which selects them on every row with cross-fitted nuisances.- working_basisscikit-learn
transformerorNone, default=None Maps the covariates to the dictionary the working models are selected from.
Nonetakes a standardized linear term, hinge terms at five quantile knots and pairwise products for each continuous covariate, and indicators for a covariate with few values.- source_learner
estimatororNone, default=None Learner for the trial-membership probabilities
P(S = 1 | W, A)andP(S = 1 | W).Nonetakesmodels.treatment_learner, then the default Super Learner.- force_armbool, default=False
Leave the arm column
Aof the bias model unpenalized, as theatmlepackage does by default (force_A = TRUE).Falsepenalizes it like every other column except the constant, which is the default here because a forcedAgives each external arm a free mean shift: the external rows then carry no information on the effect’s level, and the efficiency bound is the trial-only one (on the exact lawa0the standard deviation of the influence function is 0.48 of the trial-only bound withApenalized and 1.00 withAforced). With controls-only external data there is no arm column and the setting has no effect.
- models
- Raises:
MethodConfigurationErrorWhen
formis not"cv"or"pooled", whenforce_armis not a bool, whenrepeatsis above one, whenform="cv"has fewer than three folds or cross-fitting off, or when a field the method does not read differs from its default.
See also
TrialWithExternalDataThe design this method fits.
TrialATEThe effect it estimates.
cleverly.estimators.atmle_result.AdaptiveTMLEResultWhat a fit returns.
Examples
>>> from cleverly import AdaptiveTMLEMethod, CrossFitting >>> method = AdaptiveTMLEMethod(form="pooled", cross_fitting=CrossFitting(n_folds=3)) >>> method.name, method.form, method.cross_fitting.n_folds ('atmle', 'pooled', 3)
A setting the method does not read is refused before any fit:
>>> from cleverly import MethodConfigurationError >>> try: ... AdaptiveTMLEMethod().with_overrides(n_bootstrap=200) ... except MethodConfigurationError as error: ... print(str(error).split(";")[1].strip()) inference.n_bootstrap does not apply. Remove it.
Methods#
- AdaptiveTMLEMethod.estimator_kwargs(*, longitudinal: bool = False) dict[str, Any][source]#
Translate this configuration for the adaptive TMLE engine.
The learners are returned as declared: the fit resolves
Noneto the default library once it knows the outcome family, andg_bounds="auto"once it knows the number of rows.- Parameters:
- longitudinalbool
Must be false, because adaptive TMLE is derived for one treatment decision.
- Returns:
- Raises:
MethodConfigurationErrorWhen
longitudinalis true.
Attributes#
- AdaptiveTMLEMethod.cross_fitting: CrossFitting = CrossFitting(enabled=True, n_folds=5, learner_folds=5, repeats=1, stratify_by='none', targeting_scheme='pooled', fold_evaluation=False, split_plan=None)#