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). See cleverly.longitudinal.ipsi for the recursion.

IPSI is Kennedy’s odds tilt. lmtp::ipsi is the risk-ratio tilt of Díaz et al. (2023), which this package fits as RiskRatioTilt with LTMLE or SDR.

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 of simultaneous=True covers 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:
regimensmapping, sequence of Incremental, or sequence of regimens

The plans. A sequence of Incremental objects is shorthand: each one tilts every node, and its name is the label. One Incremental applies 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 value Incremental(2.0) tilts every node. A DynamicRegimen can 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.

referencestr or None

The regimen every contrast is taken against, the first declared by default. It must be one of regimens: list Incremental(1.0) to contrast with the natural course. Under dropout, \(\psi(1)\) is the mean with dropout prevented, not the observed mean.

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 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 influence-function values are 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. It defaults to outcome_learner, and otherwise to a regression SuperLearner with no clip, as npcausal::ipsi fits it.

treatment_learnerobject or None

The treatment mechanism at each node. At a tilt node it is part of the estimand.

censoring_learnerobject or None

The censoring mechanism at each node.

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 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_foldsint

The inner folds of a default SuperLearner.

g_boundsfloat or tuple of float

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_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 over the plans and horizons. The band covers the declared plans only, not a continuum of \(\delta\).

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 study measures the IPSI bootstrap, so 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.

hazard_pooling{“node”, “pooled”}

The pooling, as for LTMLE.

repeatsint

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

max_memory_bytesint or None

The budget of the memory guard, as for SDR.

**refusedAny

alpha, max_iter, tol, stopping, step_bound, step_search, iterate, targeting and fluctuation, which raise MethodConfigurationError because the estimator fits no fluctuation, and each point-treatment keyword that LTMLE refuses. ratio_trim other than None raises CapabilityError (IPSI_RATIO_TRIM_REFUSAL).

See also

LTMLE

The targeted estimator of static, dynamic and known-policy plans.

ipsi

The 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:
dataDataFrame or LongitudinalData

One wide frame, a row per unit and a column per node, or a container.

**kwargsAny

The column and declaration keywords of LTMLE.fit().

Returns:
LongitudinalResult

The plan estimates, their contrasts or working-model coefficients, and the fits behind them.

Raises:
MethodConfigurationError

When data is a point-treatment CausalData.

Attributes#