cleverly.longitudinal.SurvivalCTMLE#

class cleverly.longitudinal.SurvivalCTMLE(regimens: Any, *, reference: str | None = None, horizons: Sequence[int] | None = None, outcome_learner: Any | None = None, n_folds: int = 1, learner_folds: int = 5, g_bounds: Any = (0.01, 1.0), alpha: float = 0.9995, alpha_sig: float = 0.05, max_iter: int = 20, tol: float = 1e-10, selection_folds: int = 5, selection_split: Sequence[int] | None = None, penalty: bool = True, hazard_pooling: str = 'node', random_state: int | None = None, run_id: str | None = None, n_jobs: int = 1, survival_model: str = 'hazard', targeting: str = 'iterative', simultaneous: bool = False, n_multiplier: int = 10000, multiplier_kind: str = 'mammen', band_scale: str = 'logit', band_reference: str = 'normal', repeats: int = 1, n_bootstrap: int = 0, bootstrap_resampling: Any = 'auto', bootstrap_interval: Any = 'percentile', stopping: Any = 'relative', step_bound: float | None = None, step_search: bool = True, iterate: Any = 'last', step_size: float = 0.001, q_bounds: tuple[float, float] | None = None, msm: Any = None, node_bounds: Mapping[Any, Any] | None = None, ratio_trim: float | None = None, isotonic: bool = False, pseudo_learner: Any | None = None, treatment_learner: Any | None = None, censoring_learner: Any | None = None, competing_learner: Any | None = None, density_bins: int | None = None, ratio: str = 'density', strategy: str = 'greedy', patience: int | None = None, candidates: Any = None, ordering: Any = None, preorder: str | None = None, lambdas: Any = None, treatment_candidates: Any = None, oat_design: str | None = None, selection_inner_folds: int = 2, selection_estimand: str | None = None, loss: str = 'auto', **refused: Any)[source]#

Collaborative TMLE of a treatment-specific risk curve (Stitelman and van der Laan 2010).

For each horizon and each static arm of a binary baseline treatment, the fit selects a main-term logistic treatment model and a main-term pooled logistic censoring model by the greedy collaborative search of the source, and reports the risk of the arm from that selection’s targeted event hazard. The module docstring of cleverly.longitudinal.collaborative states the search, the loss and the penalty. Every estimate is a point: std_error, ci and pvalue raise, and plugin_std_error and plugin_interval keep the hazard influence curve at the selected state as a diagnostic. The memory guard of LTMLE does not check this fit: its memory is outside that guard’s calibration.

Parameters:
regimensmapping or sequence

Static arms of the binary baseline treatment, such as {"a1": 1, "a0": 0}.

referencestr or None, default=None

The regimen every contrast is taken against; the first declared by default.

horizonssequence of int or None, default=None

The nodes the curve is reported at. Each horizon runs its own selections, so naming the horizons you need saves time.

outcome_learnerestimator or None, default=None

The learner of the initial event hazard \(\hat Q_2\), fitted once on the full data and held fixed through the selection. None uses the default Super Learner.

n_foldsint, default=1

The outer split. 1 fits \(\hat Q_2\) and every candidate in sample, the source’s setting. At 2 or more, \(\hat Q_2\) and each full-data candidate are fitted out of fold.

learner_foldsint, default=5

The internal folds of a Super Learner outcome learner.

g_boundsfloat or tuple of float, default=(0.01, 1.0)

The bound of each cumulative mechanism product, as on hazard LTMLE.

alphafloat, default=0.9995

The probability bound of every hazard.

alpha_sigfloat, default=0.05

The significance level of the plug-in diagnostic interval.

max_iterint, default=20

Outer iterations of each targeting solve.

tolfloat, default=1e-10

The relative-score tolerance of each targeting solve.

selection_foldsint, default=5

The folds of the cross-validated move count. The source does not state its count.

selection_splitsequence of int or None, default=None

Fold labels 0 to V - 1 per row, in place of the random selection split.

penaltybool, default=True

Whether the risk adds the printed penalty (24) of the source.

hazard_pooling{“node”, “pooled”}, default=”node”

How \(\hat Q_2\) pools the nodes. The censoring candidates always pool the nodes with one indicator per node.

random_stateint or None, default=None

Seeds the outer split, the selection split and the outcome learner.

run_idstr or None, default=None

A label for the run record.

n_jobsint, default=1

Workers of the outcome learner.

See also

cleverly.longitudinal.LTMLE

Hazard targeting with a fitted mechanism, with intervals.

cleverly.estimators.CTMLE

Collaborative TMLE of a point-treatment mean.

Notes

The other keywords of LTMLE and of point CTMLE are accepted only at their defaults, and every other value raises before any learner with the reason the design records: a band, a bootstrap, a repeated split, a non-greedy strategy, a learner for the mechanisms, a projection and a targeting rule each have no source here. loss="loglik" equals the default "auto".

Examples

>>> import numpy as np
>>> import pandas as pd
>>> from sklearn.linear_model import LogisticRegression
>>> from cleverly.longitudinal import LongitudinalData, SurvivalCTMLE
>>> rng = np.random.default_rng(0)
>>> n = 300
>>> w1, w2 = rng.normal(size=n), rng.normal(size=n)
>>> a = rng.binomial(1, 1 / (1 + np.exp(-0.5 * w1)))
>>> event = rng.binomial(1, 1 / (1 + np.exp(0.5 - 0.6 * w1 + 0.5 * a)))
>>> time = np.where(event == 1, rng.integers(1, 3, size=n), 2).astype(float)
>>> frame = pd.DataFrame({"time": time, "event": event, "A": a, "W1": w1, "W2": w2})
>>> data = LongitudinalData.from_time_to_event(
...     frame, time="time", event="event", treatment="A", baseline=["W1", "W2"]
... )
>>> result = SurvivalCTMLE(
...     {"a1": 1, "a0": 0},
...     reference="a0",
...     outcome_learner=LogisticRegression(),
...     selection_folds=3,
...     random_state=0,
... ).fit(data)
>>> sorted(result.selection)
[('a0', 1), ('a0', 2), ('a1', 1), ('a1', 2)]
>>> result.inference_status
'working_mechanism_plugin'

Methods#

Attributes#