cleverly.ModelSpec#
- class cleverly.ModelSpec(outcome_learner: Any = None, treatment_learner: Any = None, missingness_learner: Any = None, intermediate_learner: Any = None, pseudo_learner: Any = None, censoring_learner: Any = None, density_bins: int | None = None, ratio: Literal['density', 'classifier'] = 'density', screen_treatment: bool = False, screen_threshold: float = 0.1, min_retain: int | None = None, outcome_by_arm: bool = False, survival_model: Literal['iterated_mean', 'hazard'] = 'iterated_mean')[source]#
Configure nuisance learning for TMLE methods.
- Parameters:
- outcome_learner
estimatororNone Outcome-regression learner.
Noneuses the default library.- treatment_learner
estimatororNone Treatment-mechanism learner.
- missingness_learner
estimatororNone Observation learner. It fits the outcome observation mechanism and, for a declared missing treatment, the treatment observation mechanism
P(Delta_A = 1 | W).- intermediate_learner
estimatororNone Intermediate-variable learner for controlled direct effects.
- pseudo_learner
estimatororNone Sequential pseudo-outcome learner.
- censoring_learner
estimatororNone Longitudinal observation-mechanism learner.
- density_bins
intorNone Number of bins for a continuous-treatment conditional density.
Nonegrows the count with the sample,max(20, ceil(2 n^(1/3))). A growing count is necessary for a consistent density, and the hazard learner must also be consistent.- ratio{“density”, “classifier”}
How a modified treatment policy’s density ratio is estimated.
"density"divides two fitted conditional densities."classifier"reads the odds of a stacked classifier (Díaz et al. 2023, Section 5.4). It applies to a point fit withModifiedTreatmentPolicyand to a longitudinal fit with a continuous or vector node. A study refuses"classifier"where no policy ratio is estimated.- screen_treatmentbool
Whether to screen treatment-mechanism covariates by correlation.
- screen_threshold
float Absolute correlation threshold used by screening.
- min_retain
intorNone Minimum number of covariates retained by screening.
- outcome_by_armbool
Whether to fit one outcome regression per treatment arm, each on the arm’s rows and the covariates alone (R’s
drtmle(stratify=TRUE)). The default fits one regression on the covariates and the treatment. A continuous dose has no arms and is refused, and so is a longitudinal design.- survival_model{“iterated_mean”, “hazard”}
How a longitudinal fit models a survival curve.
"hazard"targets the cause-specific hazards of a held baseline treatment; seeLTMLE. A point-treatment fit refuses"hazard".
- outcome_learner
See also
TMLEMethodMethod configuration this object is the model half of.
cleverly.SuperLearnerEnsemble to pass when one learner is not enough.
CrossFittingHow the learners set here are fitted out of fold.
Examples
>>> from cleverly import ModelSpec >>> from sklearn.linear_model import LinearRegression >>> models = ModelSpec(outcome_learner=LinearRegression()) >>> type(models.outcome_learner).__name__ 'LinearRegression'
Fit one outcome regression for each treatment arm, as
drtmle(stratify=TRUE)does:>>> ModelSpec(outcome_learner=LinearRegression(), outcome_by_arm=True).outcome_by_arm True