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 LTMLE with no fluctuation, and the estimate is the weighted mean of the first node’s prediction. See cleverly.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_bounds moves only those diagnostics.

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

The regimens, as for LTMLE. Modified treatment policies are accepted: the recursion predicts each node regression at the policy’s dose.

referencestr or None

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

horizonssequence of int or None

The survival horizons, as for LTMLE.

outcome_learnerobject or None

The regression at the reported horizon. The default is a main-terms GLM.

pseudo_learnerobject or None

The regression of every earlier node. It defaults to outcome_learner.

treatment_learnerobject or None

The treatment mechanism of the diagnostics. The default is a GLM.

censoring_learnerobject or None

The censoring mechanism of the diagnostics. The default is a GLM.

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

Must be 1. The estimator fits in sample.

g_boundsfloat or tuple of float

The cumulative bound of the diagnostic clever covariate.

q_boundstuple of float or None

The known support of a continuous outcome. A binomial-family GLM on a continuous outcome needs it.

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 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. The draws report a bootstrap sd and no percentile inference.

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

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

density_binsint or None

The bin count of a continuous node’s diagnostic density.

ratio{“density”, “classifier”}

How a continuous node’s diagnostic policy ratio is estimated.

msmNone

Refused: a working model over regimens is fitted by LTMLE or SDR.

**refusedAny

alpha, max_iter and tol, which raise TypeError because the estimator fits no fluctuation, and each point-treatment keyword that LTMLE refuses. ratio_trim other than None and hazard_pooling other than "node" raise CapabilityError.

See also

SequentialIPW

The inverse probability weighted estimator of the same parameters.

LTMLE

The targeted estimator of the same parameters.

gcomp

The 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'

Methods#

Attributes#