cleverly.longitudinal.SequentialGComputation#
- class cleverly.longitudinal.SequentialGComputation(regimens: Any, *, outcome_learner: Any | None = None, **kwargs: Any)[source]#
Sequential g-computation of a treatment regimen over time.
The iterated conditional expectation form of the longitudinal g-formula (Bang and Robins 2005, Section 4). It runs the backward sequential regression of
LTMLEwith no fluctuation, and the estimate is the weighted mean of the first node’s prediction. Seecleverly.longitudinal.baselines.The estimate is consistent only when every outcome regression is correctly specified. With every regression a
GLM, the interval is the stacked estimating equation of the GLM fits and the estimate (Stefanski and Boos 2002, Section 2). That interval is valid for the target only when every GLM is correctly specified. Under misspecification it covers the limit of the misspecified fit. With another learner the fit takes the"adaptive_baseline_plugin"status: the point estimate stands, and the diagnostic curve is the efficient influence curve at the untargeted fits.The treatment and censoring mechanisms are fitted for the positivity diagnostics only. The estimate does not read them, and
g_boundsmoves only those diagnostics.- Parameters:
- regimens
mapping,Regimen,DynamicRegimen,orsequenceofregimens The regimens, as for
LTMLE. Modified treatment policies are accepted: the recursion predicts each node regression at the policy’s dose.- reference
strorNone The regimen every contrast is taken against, as for
LTMLE.- horizonssequence
ofintorNone The survival horizons, as for
LTMLE.- outcome_learner
objectorNone The regression at the reported horizon. The default is a main-terms
GLM.- pseudo_learner
objectorNone The regression of every earlier node. It defaults to
outcome_learner.- treatment_learner
objectorNone The treatment mechanism of the diagnostics. The default is a
GLM.- censoring_learner
objectorNone The censoring mechanism of the diagnostics. The default is a
GLM.- 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 Must be
1. The estimator fits in sample.- g_bounds
floatortupleoffloat The cumulative bound of the diagnostic clever covariate.
- q_bounds
tupleoffloatorNone The known support of a continuous outcome. A binomial-family GLM on a continuous outcome needs it.
- 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 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. The draws report a bootstrap sd and no percentile inference.- bootstrap_resampling{“auto”, “iid”, “cluster”}
"auto"resamples clusters whenid=is declared, and rows otherwise.- density_bins
intorNone The bin count of a continuous node’s diagnostic density.
- ratio{“density”, “classifier”}
How a continuous node’s diagnostic policy ratio is estimated.
- msm
None Refused: a working model over regimens is fitted by
LTMLEorSDR.- **refused
Any alpha,max_iterandtol, which raiseTypeErrorbecause the estimator fits no fluctuation, and each point-treatment keyword thatLTMLErefuses.ratio_trimother thanNoneandhazard_poolingother than"node"raiseCapabilityError.
- regimens
See also
SequentialIPWThe inverse probability weighted estimator of the same parameters.
LTMLEThe targeted estimator of the same parameters.
gcompThe one-call form of this estimator.
Examples
>>> from cleverly.datasets import make_longitudinal >>> from cleverly.longitudinal import SequentialGComputation >>> frame, _ = make_longitudinal(n=300, seed=0) >>> result = SequentialGComputation({"always": 1, "never": 0}).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.inference_status 'influence_curve'