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. Only TrialWithExternalData takes this method.

The method reads the learners of ModelSpec, enabled, n_folds, learner_folds and split_plan of CrossFitting, g_bounds of Targeting, alpha of Inference and random_state and run_id of Runtime. 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:
modelsModelSpec

outcome_learner fits the outcome regressions, treatment_learner the pooled treatment mechanism, and missingness_learner the outcome-observation mechanism. None takes the default Super Learner library.

cross_fittingCrossFitting, 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_folds also sets the folds of the cross-validation that chooses each lasso penalty. form="cv" needs enabled=True and at least three folds. form="pooled" with enabled=False fits every nuisance on every row. A split_plan supplies the outer folds in place of a drawn split. repeats above one is refused.

targetingTargeting

g_bounds bounds the treatment, trial-membership and observation probabilities.

inferenceInference

alpha sets the interval’s level.

runtimeRuntime

Seed and run identifier.

namestr

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 transformer or None, default=None

Maps the covariates to the dictionary the working models are selected from. None takes 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_learnerestimator or None, default=None

Learner for the trial-membership probabilities P(S = 1 | W, A) and P(S = 1 | W). None takes models.treatment_learner, then the default Super Learner.

force_armbool, default=False

Leave the arm column A of the bias model unpenalized, as the atmle package does by default (force_A = TRUE). False penalizes it like every other column except the constant, which is the default here because a forced A gives 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 law a0 the standard deviation of the influence function is 0.48 of the trial-only bound with A penalized and 1.00 with A forced). With controls-only external data there is no arm column and the setting has no effect.

Raises:
MethodConfigurationError

When form is not "cv" or "pooled", when force_arm is not a bool, when repeats is above one, when form="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

TrialWithExternalData

The design this method fits.

TrialATE

The effect it estimates.

cleverly.estimators.atmle_result.AdaptiveTMLEResult

What 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 None to the default library once it knows the outcome family, and g_bounds="auto" once it knows the number of rows.

Parameters:
longitudinalbool

Must be false, because adaptive TMLE is derived for one treatment decision.

Returns:
dict of str to Any

Engine keyword arguments.

Raises:
MethodConfigurationError

When longitudinal is 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)#
AdaptiveTMLEMethod.force_arm: bool = False#
AdaptiveTMLEMethod.form: Literal['cv', 'pooled'] = 'cv'#
AdaptiveTMLEMethod.name: str = 'atmle'#
AdaptiveTMLEMethod.source_learner: Any = None#
AdaptiveTMLEMethod.working_basis: Any = None#