cleverly.longitudinal.IPSI#
- class cleverly.longitudinal.IPSI(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', hazard_pooling: str = 'node', repeats: int = 1, max_memory_bytes: int | None = None, **refused: Any)[source]#
Incremental propensity-score interventions over time, by Kennedy’s estimator.
An odds tilt multiplies each unit’s odds of treatment at a node by \(\delta_t\) (Kennedy 2019, Equation (1)). A node with three or more levels takes one factor per level, \(q_t(a \mid H_t) \propto \delta_{t,a}\pi_t(a \mid H_t)\), declared as
Incremental({level: factor}). The plan is identified without treatment positivity at its tilt nodes (Theorem 1). The estimator is Algorithm 1 of Kennedy (2019), with the dropout weights of Kim, Kennedy and Naimi (2021, Algorithm 1): the mean of the efficient influence function at nuisances fitted by the training-fold recursion. It fits no fluctuation. The influence function has a mechanism term at each tilt node, so the estimator is not doubly robust: the treatment mechanism must be consistent at every tilt node (Kennedy 2019, Section 3.3). Seecleverly.longitudinal.ipsifor the recursion.IPSIis Kennedy’s odds tilt.lmtp::ipsiis the risk-ratio tilt of Díaz et al. (2023), which this package fits asRiskRatioTiltwithLTMLEorSDR.A repeated outcome. With
outcome=Repeated([...])the fit reports one mean per 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. The functional at horizon \(h\) is Theorem 3.1 of Kim, Kennedy and Naimi (2021) at \(t = h\). The influence function is their Theorem 4.1 on the prefix. The band ofsimultaneous=Truecovers the declared tilts and horizons jointly, which is their Theorem 5.1 restricted to the declared finite grid of \(\delta\). It does not cover the values of \(\delta\) between the declared ones. The estimator is singly robust: a wrong treatment mechanism leaves a bias that a correct outcome regression does not remove.- Parameters:
- regimens
mapping, sequenceofIncremental,orsequenceofregimens The plans. A sequence of
Incrementalobjects is shorthand: each one tilts every node, and itsnameis the label. OneIncrementalapplies to every node, so a scalar needs two levels at each node and a mapping key must be a level of each node. A mapping valueIncremental(2.0)tilts every node. ADynamicRegimencan hold a different tilt per node, and label, rule and known-policy nodes beside the tilts. A plan with no tilt node is accepted, so a tilt can be contrasted with a static plan on one fit.- reference
strorNone The regimen every contrast is taken against, the first declared by default. It must be one of
regimens: listIncremental(1.0)to contrast with the natural course. Under dropout, \(\psi(1)\) is the mean with dropout prevented, not the observed mean.- horizonssequence
ofintorNone The horizons of a survival or repeated outcome, as for
LTMLE.Nonereports every node. A repeated outcome reports one mean per 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 influence-function values are 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. It defaults to
outcome_learner, and otherwise to a regressionSuperLearnerwith no clip, asnpcausal::ipsifits it.- treatment_learner
objectorNone The treatment mechanism at each node. At a tilt node it is part of the estimand.
- censoring_learner
objectorNone The censoring mechanism at each node.
- 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 every nuisance on its training rows alone, and its held-out rows take the influence function from that fold’s models (Kennedy 2019, Algorithm 1). One fold is Kennedy’s Algorithm 2, which needs Donsker-type conditions.
- learner_folds
int The inner folds of a default
SuperLearner.- g_bounds
floatortupleoffloat The bound pair of the cumulative censoring, label, rule and policy factors. The tilt factor is never bounded. 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 over the plans and horizons. The band covers the declared plans only, not a continuum of \(\delta\).
- 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 study measures the IPSI bootstrap, so the draws report a bootstrap sd and no percentile inference.- bootstrap_resampling{“auto”, “iid”, “cluster”}
"auto"resamples clusters whenid=is declared, and rows otherwise.- hazard_pooling{“node”, “pooled”}
The pooling, as for
LTMLE.- repeats
int How many independent draws of the outer split the fit combines by their median, as for
LTMLE.- max_memory_bytes
intorNone The budget of the memory guard, as for
SDR.- **refused
Any alpha,max_iter,tol,stopping,step_bound,step_search,iterate,targetingandfluctuation, which raiseMethodConfigurationErrorbecause the estimator fits no fluctuation, and each point-treatment keyword thatLTMLErefuses.ratio_trimother thanNoneraisesCapabilityError(IPSI_RATIO_TRIM_REFUSAL).
- regimens
See also
LTMLEThe targeted estimator of static, dynamic and known-policy plans.
ipsiThe one-call form of this estimator.
Examples
>>> from sklearn.linear_model import LinearRegression, LogisticRegression >>> from cleverly.datasets import make_longitudinal >>> from cleverly.interventions import Incremental >>> from cleverly.longitudinal import IPSI >>> frame, _ = make_longitudinal(n=200, seed=0) >>> result = IPSI( ... [Incremental(1.0), Incremental(2.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[odds x2 vs natural course]', 'ey_regimen[natural course]', 'ey_regimen[odds x2]'] >>> result.config.estimator 'ipsi'
Methods#
- IPSI.fit(data: Any, **kwargs: Any) LongitudinalResult[source]#
Fit on a wide dataframe, or on an already-built
LongitudinalData.The keywords are those of
LTMLE.fit(). A declared treatment mechanism at a tilt node removes that node’s mechanism term from the influence function, because the tilt is then a known policy (Kennedy 2019, Section 3.3).- Parameters:
- data
DataFrameorLongitudinalData One wide frame, a row per unit and a column per node, or a container.
- **kwargs
Any The column and declaration keywords of
LTMLE.fit().
- data
- Returns:
LongitudinalResultThe plan estimates, their contrasts or working-model coefficients, and the fits behind them.
- Raises:
MethodConfigurationErrorWhen
datais a point-treatmentCausalData.