cleverly.EPMethod#

class cleverly.EPMethod(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=10, 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 = 'ep', sieve: Any = None, final_learner: Any = None)[source]#

Configure the EP learner of a conditional effect curve.

The EP learner (van der Laan, Carone and Luedtke, arXiv:2402.01972v2, a preprint) fits the outcome regressions and the treatment model out of fold, adjusts the outcome regressions by one weighted logistic regression on a sieve of the modifiers, and fits the curve to the adjusted contrast. The curve has no confidence interval. It estimates a cleverly.ConditionalContrast; with model=None the target is the conditional effect itself, approximated within the final learner’s class.

Parameters:
modelsModelSpec

Nuisance learners and related model settings.

cross_fittingCrossFitting

Sample-splitting settings. The fit needs out-of-fold nuisances, so enabled=False, repeats above 1 and fold_evaluation=True (the cv_evaluation=True shortcut) are refused.

targetingTargeting

Only g_bounds, q_bounds, nuisance_bound and submodel_alpha are read; the EP learner fits no fluctuation, and any other non-default setting is refused.

inferenceInference

Must be the default: the EP curve has no interval (R1 of the P1 plan).

runtimeRuntime

Seed, run identifier, and parallelism.

namestr

Stable method name.

sieveSieve or None

The debiasing sieve of a fit with model=None. None uses Sieve.default(modifiers): additive cosines of the continuous modifiers and indicators of the categorical ones, sizes 1 to 6, chosen by cross-validation. A fixed size or a declared schedule n -> size skips the cross-validation. With model= declared on the estimand, the model is the sieve and this stays None.

final_learnerAny

A learner of the curve on the modifier columns, in place of the default final stage on the sieve basis; model=None only. On the difference scale it is a regressor fitted to the adjusted contrast. On the log-ratio scale it is a classifier with predict_proba whose fit accepts sample_weight: each row becomes a pair, label 1 weighted by the row weight times the adjusted treated mean and label 0 by the row weight times the adjusted reference mean, and the curve is the logit of the class-1 probability, clipped to the range of the fitted shares. The two rows of a pair share a groups code. HistGradientBoostingClassifier turns on early stopping above 10,000 rows, which the doubled data reach above 5,000 rows, and then validates on a random split that separates pairs; declare early_stopping=False to keep every pair in the fit.

See also

cleverly.ConditionalContrast

The estimand this method fits.

cleverly.bases.Sieve

The sieve and its size rule.

TMLEMethod

The projection fit with intervals, for a declared model.

Examples

>>> import numpy as np
>>> import pandas as pd
>>> from sklearn.linear_model import LogisticRegression
>>> from cleverly import CausalStudy, ConditionalContrast, EPMethod, PointTreatment
>>> from cleverly.bases import Cosine, Modifiers, Sieve
>>> rng = np.random.default_rng(0)
>>> w = rng.uniform(0.0, 1.0, 400)
>>> a = rng.binomial(1, 0.5, 400)
>>> y = rng.binomial(1, 0.3 + 0.3 * a * w)
>>> study = CausalStudy(
...     pd.DataFrame({"W": w, "A": a, "Y": y}),
...     design=PointTreatment(outcome="Y", treatment="A", adjustment=("W",)),
... )
>>> effect = study.identify(ConditionalContrast(Modifiers(["W"], domains={"W": (0.0, 1.0)})))
>>> method = EPMethod(sieve=Sieve(Cosine(["W"], size=3), size=2)).with_overrides(
...     outcome_learner=LogisticRegression(),
...     treatment_learner=LogisticRegression(),
...     random_state=0,
... )
>>> curve = effect.estimate(method)
>>> curve.fitted_method, curve.inference_status, curve.sieve.chosen
('ep', 'no_interval', 2)

Methods#

EPMethod.with_overrides(**overrides: Any) → EPMethod[source]#

Return a copy with flat shortcuts normalized by concern.

Parameters:
**overridesAny

The shortcuts TMLEMethod.with_overrides() takes, plus sieve and final_learner.

Returns:
EPMethod

New immutable configuration.

Attributes#

EPMethod.final_learner: Any = None#
EPMethod.name: str = 'ep'#
EPMethod.sieve: Any = None#