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
LTMLEand 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. Seecleverly.longitudinal.sdrfor 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 ofsimultaneous=Truecovers every plan and horizon jointly, from the stacked influence curves.A transform can leave
[0, 1], so the default pseudo learner is a regressionSuperLearnerwith no clip, aslmtpfits it. A pseudo learner that clips is accepted, and it moves the estimate away fromlmtp_sdr. A learner that reads its target as a probability raises its own error on a target outside[0, 1].- Parameters:
- regimens
mapping,Regimen,DynamicRegimen,orsequenceofregimens The regimens, as for
LTMLE.- reference
strorNone The regimen every contrast is taken against, as for
LTMLE.- horizonssequence
ofintorNone The horizons of a survival or repeated outcome, as for
LTMLE.Nonereports 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.- msm
MSMorNone 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_learner
objectorNone The regression at the reported horizon, as for
LTMLE.- pseudo_learner
objectorNone The regression of every earlier node, on a real-valued target. It defaults to
outcome_learner, and otherwise to a regressionSuperLearnerwithclip=None.- treatment_learner
objectorNone The treatment mechanism at each node, as for
LTMLE.- censoring_learner
objectorNone The censoring mechanism at each node, as for
LTMLE.- competing_learner
objectorNone The learner of each eliminated competing event (
eliminate=on the data), fit on the rows that passed censoring at the node.Noneuses the censoring learner.- n_folds
int 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_folds
int The inner folds of a default
SuperLearner.- g_bounds
floatortupleoffloat 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_bounds
tupleoffloatorNone The bounds of a continuous outcome, as for
LTMLE.- alpha_sig
float Significance level for confidence intervals.
- simultaneousbool
Whether to report simultaneous confidence bands, as for
LTMLE.- n_multiplier
int, 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_state
intorNone The seed of the outer split, inherited by every learner
random_statethat isNone, including a Super Learner’s candidates.- run_id
strorNone An identifier of your own, recorded on
LongitudinalResult.provenance.- n_jobs
int Worker count for the parallel fan-out.
- n_bootstrap
int Full-refit bootstrap replicates,
0for none. No registered row lists a bootstrap kind for anSDRfit, so its intervals carry the labelexperimental. The replicates are computed as forLTMLE.- bootstrap_resampling{“auto”, “iid”, “cluster”}
"auto"resamples clusters whenid=is declared, and rows otherwise.- bootstrap_interval{“percentile”, “bca”}, default=”percentile”
The pointwise bootstrap interval, as for
LTMLE. It carries the labelexperimental.- density_bins
intorNone 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_trim
floatorNone The per-node ratio trim, as for
LTMLE. Each partial weight \(W_{t,s}\) is then the product of the trimmed ratios, as inlmtp(trimmed_factors()).- hazard_pooling{“node”, “pooled”}
The pooling, as for
LTMLE. Each cross-fitted fold pools its own censoring model.- repeats
int 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_bytes
intorNone The budget of the memory guard, as for
LTMLE: the fit predicts the peak of the whole call before any learner and raisesLongitudinalMemoryError, aMethodConfigurationError, when the prediction exceeds the budget.Nonereads 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 ofdocs/technical-reference/longitudinal-tmle.mdlists, it is an extrapolation. The hazard path limit thatLTMLEalso applies does not arise here.- **refused
Any alpha,max_iter,tol,stopping,step_bound,step_searchanditerate, which raiseMethodConfigurationErrorbecause the estimator fits no fluctuation, and each point-treatment keyword thatLTMLErefuses.
- regimens
See also
LTMLEThe targeted estimator of the same parameters.
sdrThe 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'