cleverly.survival.ContinuousSurvivalTMLE#
- class cleverly.survival.ContinuousSurvivalTMLE(horizons: Sequence[float], *, restricted_horizons: Sequence[float] = (), arms: Mapping[str, Any] | None = None, reference: str | None = None, causes: Mapping[int, str] | None = None, cross_fit: bool = True, n_folds: int = 10, learner_folds: int = 5, hazard_library: Sequence[Any] | None = None, censoring_library: Sequence[Any] | None = None, treatment_learner: Any = None, norm: Literal['covariance', 'variance', 'euclidean'] = 'covariance', g_bounds: Literal['auto'] | float = 'auto', max_iter: int = 500, step_size: float = 0.1, tol: float | None = None, alpha: float = 0.05, random_state: int | None = None, tilt: Literal['all', 'factual'] = 'all', simultaneous: bool = False, n_multiplier: int = 10000, multiplier_kind: str = 'mammen', band_scale: str = 'logit', variance: Literal['switched', 'influence_curve'] = 'switched', max_memory_bytes: int | None = None, n_jobs: int | None = 1, n_bootstrap: int = 0, bootstrap_interval: Literal['percentile', 'bca'] = 'percentile')[source]#
One-step TMLE of cause-specific absolute risks in continuous time.
- Parameters:
- horizonssequence
offloat The target times \(t_1 < \dots < t_K\).
- restricted_horizonssequence
offloat The restriction times \(\tau_1 < \dots < \tau_R\) of the restricted means. Each \(\tau\) adds the restricted mean time lost to each cause, \(E \int_0^\tau F_j(u \mid a, L)\, du\), of both arms to the targets the walk solves, so
ContinuousSurvivalResult.rmtl()andrmst()can read them. The extra targets change the walk, so the risks of such a fit differ slightly from those of a fit without them.- arms
mappingofstrtolevel,orNone The label of each treatment level, two levels.
Nonelabels the two observed levels bystr(level).- reference
strorNone The label of the comparison arm of the contrasts.
Nonetakes the first label.- causes
mappingofinttostr,orNone The label of each nonzero event code.
Nonereads one code1as one event, and several codes as competing causes labelledstr(code).- cross_fitbool
Fit every nuisance out of fold on
n_foldsfolds, selecting each model inside the training folds.Falsefits each on every row, the sources’ setting.- n_folds
int Cross-fitting folds.
- learner_folds
int Folds of the cross-validation that selects each nuisance model.
- hazard_librarysequence or
None Hazard learners for every cause.
Nonetakes three unstratified Cox models.- censoring_librarysequence or
None Hazard learners for the censoring hazard.
Nonetakes the same three.- treatment_learner
classifierorNone The treatment model.
Noneselects between a main-terms logistic model and an L1 logistic model by cross-validated log loss. A user learner needscross_fit=True.- norm{“covariance”, “variance”, “euclidean”}
The inner product of the universal submodel, with the covariance held at the initial fit.
- g_bounds“auto” or
float The lower bound on \(\pi(a \mid L)\, S_c(u^- \mid a, L)\).
"auto"is \(5 / (\sqrt n \log n)\).- max_iter
int The cap on accepted targeting steps.
- step_size
float The first step size.
- tol
floatorNone Stop when the largest \(|P_n D^*| / \hat\sigma\) is at or below
tol.Noneuses \(1 / (\sqrt n \log n)\) (Rytgaard and van der Laan 2024, Sec 4.3).- alpha
float Significance level of the intervals.
- random_state
intorNone Seed of the folds, the inner selection folds, the lasso members, any unseeded user learner, the off-grid diagnostic and the band.
Nonedraws one seed per fit, which the result’s stored estimator records.- tilt{“all”, “factual”}
"factual"reproduces theconcrete1.0.5 update, for the mutation control only.- simultaneousbool
Add a sup-t band over every risk and risk difference.
- n_multiplier
int Multiplier draws of the band.
- multiplier_kind
str The multiplier distribution, as
simultaneous_bands()takes.- band_scale{“logit”, “identity”}
The scale of the band of a bounded estimate.
- variance{“switched”, “influence_curve”}
The variance every estimate reports.
"switched"reads the influence-curve variance, raised to the predictable variation of the influence curve’s martingale part where the curve is sparse: where the relative standard deviation of the influence-curve variance exceedsSPARSE_INFLUENCE_THRESHOLD(0.125), the variance is the larger of the two (cleverly.inference.switched). It is never below the influence-curve variance and equals it with probability tending to one."influence_curve"reads the influence-curve variance alone. A band takes its critical value from the influence curves and its half-widths from the reported standard errors.- max_memory_bytes
intorNone The memory budget of a fit, in bytes. The walk works through blocks of units; before fitting any nuisance, the fit predicts the largest number of bytes it holds at once with no block kept between passes, which grows with
ntimes the number of targets, and refuses withMethodConfigurationErrorwhen the prediction exceeds the budget. The walk then keeps as many blocks as the budget allows and rebuilds the others on each pass, so the budget sets how long a fit runs and never what it returns.Nonereads the memory available at that moment, keeps blocks up to three quarters of it, and checks nothing (keeping every block) on a platform that does not report it. A value overrides the reading either way. Every refit of a result, and so every refutation and truncation curve, uses the value of the fit.- n_jobs
intorNone The threads the targeting walk runs its blocks of units on.
-1takes the CPUs the process may use (its affinity, capped by a control group quota) andNoneone. The result is bit for bit the same at any value; each thread holds one block’s working arrays, which the memory budget counts. Withn_bootstrap, the bootstrap refits run on this many worker processes, each walking on one thread.- n_bootstrap
int Full-refit bootstrap replicates,
0for none and otherwise at least 2. Each replicate resamples units with replacement and reruns the whole fit: the folds, every nuisance selection and the walk. Copies of a unit share every fold, the cross-fitting folds and the selections’ inner folds, so no copy is validated on its own twin. Each estimate then carries aBootstrapSummarybeside its Wald interval, and withsimultaneous=Truethe result adds a studentized bootstrap band over every risk and risk difference. When more than 1% of the refits fail, every bootstrap interval is withheld with aConvergenceWarning, and the Wald intervals stand. No bootstrap interval of this engine reads supported.- bootstrap_interval{“percentile”, “bca”}
The bootstrap interval each estimate carries: the percentile interval of the replicate estimates, or the bias-corrected and accelerated interval, with the acceleration read from the estimate’s own influence curve.
- horizonssequence
Methods#
- ContinuousSurvivalTMLE.fit(data: Any, *, time: str, event: str, treatment: str, baseline: Sequence[str]) ContinuousSurvivalResult[source]#
Fit the nuisances and target every risk.
- Parameters:
- Returns:
ContinuousSurvivalResultThe targeted risks, their contrasts and the record.
- ContinuousSurvivalTMLE.fit_data(data: Any) ContinuousSurvivalResult[source]#
Fit a
ContinuousSurvivalDatacontainer.- Parameters:
- data
ContinuousSurvivalData The validated container.
- data
- Returns:
ContinuousSurvivalResultThe targeted risks, their contrasts and the record.
- ContinuousSurvivalTMLE.refit(data: Any, *, random_state: int | None, _frozen_folds: Any = None, _frozen_plan: FoldPlan | None = None) ContinuousSurvivalResult[source]#
Fit a copy of this estimator, at the seed
random_state, todata.result.estimator.refit(result.data, random_state=result.estimator.random_state)reproduces the fit bit for bit in one process: the stored estimator carries the fit’s resolved seed, and every learner, the folds, the off-grid draws and the band read that seed.- Parameters:
- data
ContinuousSurvivalData The rows to fit.
- random_state
intorNone The seed of the copy.
Nonedraws one, which the new result’s estimator records.- _frozen_foldsarray_like or
None Private: one outer cross-fitting label per row of
data, used instead of a fresh draw. A subset refutation passes each drawn unit’s original label, so the refits keep the fit’s split. When omitted, a fit that was itself produced with frozen labels reuses them on data of the same size.- _frozen_plan
FoldPlanorNone Private: the fold plan of a fit of data of the same size, used instead of every fold draw. The outer labels, each outer fold’s inner selection labels and the generator state after the nuisance phase are the plan’s, so a refit of the same rows at the same seed reproduces that fit bit for bit, and a refit of changed event codes keeps every fold. A simulated-confounding replay passes it. When omitted, a fit that was itself produced under a plan reuses it on data of the same size.
- data
- Returns:
ContinuousSurvivalResultThe fit of the copy.
- Raises:
ValueErrorIf both
_frozen_foldsand_frozen_planare passed, or the plan does not fit the data.