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; withmodel=Nonethe target is the conditional effect itself, approximated within the final learner’s class.- Parameters:
- models
ModelSpec Nuisance learners and related model settings.
- cross_fitting
CrossFitting Sample-splitting settings. The fit needs out-of-fold nuisances, so
enabled=False,repeatsabove 1 andfold_evaluation=True(thecv_evaluation=Trueshortcut) are refused.- targeting
Targeting Only
g_bounds,q_bounds,nuisance_boundandsubmodel_alphaare read; the EP learner fits no fluctuation, and any other non-default setting is refused.- inference
Inference Must be the default: the EP curve has no interval (R1 of the P1 plan).
- runtime
Runtime Seed, run identifier, and parallelism.
- name
str Stable method name.
- sieve
SieveorNone The debiasing sieve of a fit with
model=None.NoneusesSieve.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 schedulen -> sizeskips the cross-validation. Withmodel=declared on the estimand, the model is the sieve and this staysNone.- final_learner
Any A learner of the curve on the modifier columns, in place of the default final stage on the sieve basis;
model=Noneonly. On the difference scale it is a regressor fitted to the adjusted contrast. On the log-ratio scale it is a classifier withpredict_probawhosefitacceptssample_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 agroupscode.HistGradientBoostingClassifierturns 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; declareearly_stopping=Falseto keep every pair in the fit.
- models
See also
cleverly.ConditionalContrastThe estimand this method fits.
cleverly.bases.SieveThe sieve and its size rule.
TMLEMethodThe 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)