cleverly.longitudinal.SDR#

class cleverly.longitudinal.SDR(regimens: Any, *, reference: str | None = None, horizons: Sequence[int] | None = None, msm: MSM | None = None, outcome_learner: Any | None = None, pseudo_learner: Any | None = None, treatment_learner: Any | None = None, censoring_learner: Any | None = None, competing_learner: Any | None = None, n_folds: int = 10, learner_folds: int = 5, g_bounds: float | tuple[float, float] = (0.01, 1.0), q_bounds: tuple[float, float] | None = None, alpha_sig: float = 0.05, simultaneous: bool = True, n_multiplier: int = 10000, multiplier_kind: str = 'mammen', band_scale: str = 'logit', band_reference: str = 'normal', random_state: int | None = None, run_id: str | None = None, n_jobs: int = 1, n_bootstrap: int = 0, bootstrap_resampling: Literal['auto', 'iid', 'cluster'] = 'auto', bootstrap_interval: Literal['percentile', 'bca'] = 'percentile', density_bins: int | None = None, ratio: str = 'density', ratio_trim: float | None = None, hazard_pooling: str = 'node', repeats: int = 1, variance: str = 'influence_curve', max_memory_bytes: int | None = None, **refused: Any)[source]#

Sequentially doubly robust estimation of a treatment regimen over time.

The estimator of Díaz, Williams, Hoffman and Schenck (2023, JASA 118(542), Section 5.3). It runs the backward sequential regression of LTMLE and fits no fluctuation. Instead, the regression at each node is fitted to the transformed outcome of the paper’s Equation (4), which adds every later node’s weighted residual to the carried prediction. The estimate is the weighted mean of the first node’s transform, and the influence curve is that transform minus the estimate. The estimate stays consistent when, at each node, either the outcome regression or the treatment and censoring mechanism is correct (the paper’s Lemma 4). An interval needs the rate conditions of the paper’s Theorem 4. See cleverly.longitudinal.sdr for the recursion.

A repeated outcome. With outcome=Repeated([...]) the fit reports one mean per plan and horizon. Each horizon is the end-of-study fit of the panel truncated after it, with \(Y_h\) as the outcome and each earlier \(Y_s\) as a covariate. Equation (4), Lemmas 3 and 4 and Theorem 4 of the paper apply to each horizon on its prefix. So the estimate of horizon \(h\) is consistent when, at each node \(t \le h\), the ratio or the sequential regression is consistent. The band of simultaneous=True covers every plan and horizon jointly, from the stacked influence curves.

A transform can leave [0, 1], so the default pseudo learner is a regression SuperLearner with no clip, as lmtp fits it. A pseudo learner that clips is accepted, and it moves the estimate away from lmtp_sdr. A learner that reads its target as a probability raises its own error on a target outside [0, 1].

Parameters:
regimensmapping, Regimen, DynamicRegimen, or sequence of regimens

The regimens, as for LTMLE.

referencestr or None

The regimen every contrast is taken against, as for LTMLE.

horizonssequence of int or None

The horizons of a survival or repeated outcome, as for LTMLE. None reports every node. A repeated outcome reports one mean per plan and horizon, each from the truncated end-of-study fit. Refused on a fit with one end-of-study outcome.

msmMSM or None

A working model over the regimen and horizon cells. Each cell’s first-node transform is projected onto it. The identity link is supported. A logit or log projection that does not converge is refused.

outcome_learnerobject or None

The regression at the reported horizon, as for LTMLE.

pseudo_learnerobject or None

The regression of every earlier node, on a real-valued target. It defaults to outcome_learner, and otherwise to a regression SuperLearner with clip=None.

treatment_learnerobject or None

The treatment mechanism at each node, as for LTMLE.

censoring_learnerobject or None

The censoring mechanism at each node, as for LTMLE.

competing_learnerobject or None

The learner of each eliminated competing event (eliminate= on the data), fit on the rows that passed censoring at the node. None uses the censoring learner.

n_foldsint

Outer cross-fitting folds. Above one fold, each fold fits the mechanism and the backward recursion on its training rows alone, with its own mechanism in every training row’s transform. Its held-out rows take the first-node transform from that fold’s models, and the estimate pools every row.

learner_foldsint

The inner folds of a default SuperLearner.

g_boundsfloat or tuple of float

The bound pair applied to each partial path probability \(\prod_{k=t}^{s} p_k\). At \(t = 1\) it is the cumulative bound of LTMLE. The default is (0.01, 1.0).

q_boundstuple of float or None

The bounds of a continuous outcome, as for LTMLE.

alpha_sigfloat

Significance level for confidence intervals.

simultaneousbool

Whether to report simultaneous confidence bands, as for LTMLE.

n_multiplierint, default=10_000

The number of multiplier draws behind each band.

multiplier_kind{“rademacher”, “mammen”, “normal”}, default=”mammen”

The distribution of the multiplier draws.

band_scale{“logit”, “identity”}, default=”logit”

The scale of the band of a probability or a difference of two probabilities: "logit" builds it on the logit of the estimate’s position in its range (simultaneous_bands()).

band_reference{“normal”, “t”}, default=”normal”

"t" bands each estimate at the critical value’s tail on its own Student t reference, with degrees of freedom from its influence curve (simultaneous_bands()).

random_stateint or None

The seed of the outer split, inherited by every learner random_state that is None, including a Super Learner’s candidates.

run_idstr or None

An identifier of your own, recorded on LongitudinalResult.provenance.

n_jobsint

Worker count for the parallel fan-out.

n_bootstrapint

Full-refit bootstrap replicates, 0 for none. No registered row lists a bootstrap kind for an SDR fit, so its intervals carry the label experimental. The replicates are computed as for LTMLE.

bootstrap_resampling{“auto”, “iid”, “cluster”}

"auto" resamples clusters when id= is declared, and rows otherwise.

bootstrap_interval{“percentile”, “bca”}, default=”percentile”

The pointwise bootstrap interval, as for LTMLE. It carries the label experimental.

density_binsint or None

The bin count of a continuous node’s conditional density, as for LTMLE.

ratio{“density”, “classifier”}

How a continuous node’s policy ratio is estimated, as for LTMLE.

ratio_trimfloat or None

The per-node ratio trim, as for LTMLE. Each partial weight \(W_{t,s}\) is then the product of the trimmed ratios, as in lmtp (trimmed_factors()).

hazard_pooling{“node”, “pooled”}

The pooling, as for LTMLE. Each cross-fitted fold pools its own censoring model.

repeatsint

How many independent draws of the outer split the fit combines by their median, as for LTMLE.

variance{“influence_curve”, “policy_weighted”}

The variance of every reported interval, as for LTMLE.

max_memory_bytesint or None

The budget of the memory guard, as for LTMLE: the fit predicts the peak of the whole call before any learner and raises LongitudinalMemoryError, a MethodConfigurationError, when the prediction exceeds the budget. None reads the memory available when the fit starts and checks nothing where the platform does not report it. The prediction counts the arrays the estimator holds, calibrated with GLM, logistic and linear learners, and other learners’ own memory is not counted. Outside the calibrated ranges, which the “Memory” section of docs/technical-reference/longitudinal-tmle.md lists, it is an extrapolation. The hazard path limit that LTMLE also applies does not arise here.

**refusedAny

alpha, max_iter, tol, stopping, step_bound, step_search and iterate, which raise MethodConfigurationError because the estimator fits no fluctuation, and each point-treatment keyword that LTMLE refuses.

See also

LTMLE

The targeted estimator of the same parameters.

sdr

The one-call form of this estimator.

Examples

>>> from sklearn.linear_model import LinearRegression, LogisticRegression
>>> from cleverly.datasets import make_longitudinal
>>> from cleverly.longitudinal import SDR
>>> frame, _ = make_longitudinal(n=200, seed=0)
>>> result = SDR(
...     {"always": 1, "never": 0},
...     n_folds=1,
...     outcome_learner=LinearRegression(),
...     treatment_learner=LogisticRegression(max_iter=1000),
...     censoring_learner=LogisticRegression(max_iter=1000),
... ).fit(
...     frame,
...     outcome="Y",
...     treatment=["A1", "A2"],
...     baseline=["W1", "W2"],
...     time_varying=[[], ["L2"]],
...     censoring=["C1", "C2"],
... )
>>> sorted(result.estimates)
['ate_regimen[never vs always]', 'ey_regimen[always]', 'ey_regimen[never]']
>>> result.config.estimator
'sdr'

Methods#

Attributes#