cleverly.ParametricGFormulaMethod#

class cleverly.ParametricGFormulaMethod(models: ModelSpec = ModelSpec(outcome_learner=None, treatment_learner=None, missingness_learner=None, intermediate_learner=None, pseudo_learner=None, censoring_learner=None, density_bins=None, ratio='density', screen_treatment=False, screen_threshold=0.1, min_retain=None, outcome_by_arm=False, survival_model='iterated_mean'), cross_fitting: CrossFitting = CrossFitting(enabled=False, 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', isotonic=False), inference: Inference = Inference(alpha=0.05, n_bootstrap=0, bootstrap_resampling='auto', simultaneous=True, n_multiplier='auto', multiplier_kind='rademacher'), runtime: Runtime = Runtime(random_state=None, run_id=None, n_jobs=1), name: str = 'parametric_gformula', n_draws: int = 10, n_derivative_draws: int | None = None, covariate_types: Any = None, covariate_learner: Any = None, hazard_learner: Any = None)[source]#

Configure the parametric g-formula of a longitudinal regimen.

Forward simulation of fitted covariate, outcome and hazard laws (Robins 1986; McGrath et al. 2020), fitted by cleverly.longitudinal.ParametricGFormula. The method fits in sample, so cross_fitting defaults to CrossFitting(enabled=False), and above one fold the engine refuses. It fits no fluctuation, so the fluctuation settings of Targeting stay at their defaults. A point-treatment functional and a working model over regimens refuse the method.

Parameters:
modelsModelSpec

Nuisance learners. outcome_learner fits the outcome model, and treatment_learner fits the natural-treatment models. pseudo_learner is refused.

cross_fittingCrossFitting

Sample-splitting settings. The default is in sample, and the engine refuses more than one fold.

targetingTargeting

g_bounds and q_bounds. g_bounds moves the positivity diagnostics only.

inferenceInference

Interval and resampling settings.

runtimeRuntime

Seed, run identifier, and parallelism.

namestr

Stable method name.

n_drawsint

The simulated histories per unit behind the estimate.

n_derivative_drawsint or None

The simulated histories per unit behind the derivatives. None takes the larger of n_draws and ten.

covariate_typesmapping or None

The type of each time-varying column at nodes 2..T.

covariate_learnerestimator or None

The template of every covariate model. None is a main-terms GLM.

hazard_learnerestimator or None

The template of every hazard model of a survival outcome. None is a GLM.

See also

GComputationMethod

The iterated conditional expectation form of the same parameter.

cleverly.longitudinal.ParametricGFormula

The engine this configuration is translated for.

cleverly.LongitudinalTreatment

The design whose functionals take this method.

Examples

>>> from cleverly import ParametricGFormulaMethod
>>> method = ParametricGFormulaMethod(n_draws=20)
>>> method.name, method.cross_fitting.enabled
('parametric_gformula', False)
>>> kwargs = method.estimator_kwargs(longitudinal=True)
>>> kwargs["n_draws"], kwargs["n_folds"], "alpha" in kwargs
(20, 1, False)

Methods#

ParametricGFormulaMethod.estimator_kwargs(*, longitudinal: bool = False) → dict[str, Any][source]#

Translate this configuration for the longitudinal g-formula engine.

Parameters:
longitudinalbool

Must be true, because the estimator is longitudinal.

Returns:
dict of str to Any

Engine keyword arguments, with the simulation settings.

Raises:
MethodConfigurationError

When longitudinal is false, or when a fluctuation setting differs from its default.

Attributes#

ParametricGFormulaMethod.covariate_learner: Any = None#
ParametricGFormulaMethod.covariate_types: Any = None#
ParametricGFormulaMethod.hazard_learner: Any = None#
ParametricGFormulaMethod.n_derivative_draws: int | None = None#
ParametricGFormulaMethod.n_draws: int = 10#
ParametricGFormulaMethod.name: str = 'parametric_gformula'#