cleverly.LongitudinalTreatment#

class cleverly.LongitudinalTreatment(outcome: str | Sequence[str] | Mapping[str, Sequence[str]] | Repeated, treatment: str | Sequence[str], baseline: Sequence[str], time_varying: Sequence[Sequence[str]] | None = None, censoring: Sequence[str] | None = None, cluster: str | None = None, weights: str | None = None, weights_type: Literal['probability'] = 'probability', weights_estimated: bool = False, outcome_family: Literal['gaussian', 'binomial', 'auto'] = 'auto', continuous_treatment: Sequence[str] | Mapping[str, Any] = (), treatment_probabilities: Any = None, censoring_probabilities: Any = None, dose_atoms: Mapping[str, Sequence[float]] | None = None)[source]#

Declare time-ordered roles for a longitudinal study.

Parameters:
outcomestr, sequence of str, mapping of str to sequence of str, or Repeated

End-of-study outcome, survival event nodes, competing-risk event nodes, or a Repeated outcome measured at every node.

treatmentstr or sequence of str

Treatment nodes in time order. One column name declares one baseline decision held over every node. The node count then comes from a survival or repeated outcome, else from censoring, else from time_varying, else it is one.

baselinesequence of str

Covariates observed before the first treatment. The list names at least one column.

time_varyingsequence of sequence of str or None

Covariate blocks observed before each treatment node.

censoringsequence of str or None

Observation indicators in time order. One means observed.

clusterstr or None

Independent-cluster identifier.

weightsstr or None

Probability-weight column.

weights_type{“probability”}

Interpretation of weights.

weights_estimatedbool

Whether the supplied weights were estimated from these data.

outcome_family{“auto”, “gaussian”, “binomial”}

Outcome family used by the sequential regressions.

continuous_treatmentsequence of str, or mapping of str to Support or None

The treatment nodes that hold a continuous dose. Each such node takes a modified treatment policy, such as Shift. A mapping also declares the conditional support of each dose, as cleverly.longitudinal.LTMLE.fit() takes it.

dose_atomsmapping of str to sequence of float, or None

The doses of each continuous node with a recorded point mass, as cleverly.longitudinal.LTMLE.fit() takes them.

treatment_probabilitiesmapping or None

The known treatment mechanism (a tuple of pairs, the form the design stores, is also accepted) of a sequentially randomized design: each treatment node mapped to a mapping of its levels to the column of P(A_t = level | observed past). A declared node fits no treatment learner.

censoring_probabilitiesmapping or None

The known retention probabilities (a tuple of pairs is also accepted): each censoring column mapped to the column of P(C_t = 1 | observed past). A declared node fits no censoring learner.

See also

PointTreatment

The same declaration for treatment given once.

TimeToEvent

A baseline treatment with one time and one event column.

CausalStudy

What a design is handed to along with the data.

cleverly.datasets.make_longitudinal

A frame with the nodes this example names.

Examples

Two treatment nodes, with the covariates measured before each one and an observation indicator per node:

>>> from cleverly import LongitudinalTreatment
>>> design = LongitudinalTreatment(
...     outcome="Y",
...     treatment=["A1", "A2"],
...     baseline=["W1", "W2"],
...     time_varying=[[], ["L2"]],
...     censoring=["C1", "C2"],
... )
>>> design.treatment
('A1', 'A2')

time_varying is indexed by treatment node, so the first block is empty here: no covariate is measured between baseline and the first treatment.

>>> design.time_varying
((), ('L2',))

Methods#

LongitudinalTreatment.prepare(data: Any) → LongitudinalData[source]#

Validate data and construct its ordered longitudinal representation.

Parameters:
datadataframe or LongitudinalData

Pandas, Polars, or prepared longitudinal data.

Returns:
LongitudinalData

Validated time-ordered representation.

Attributes#

LongitudinalTreatment.censoring: Sequence[str] | None = None#
LongitudinalTreatment.censoring_probabilities: Any = None#
LongitudinalTreatment.cluster: str | None = None#
LongitudinalTreatment.continuous_treatment: Sequence[str] | Mapping[str, Any] = ()#
LongitudinalTreatment.dose_atoms: Mapping[str, Sequence[float]] | None = None#
LongitudinalTreatment.outcome_family: Literal['gaussian', 'binomial', 'auto'] = 'auto'#
LongitudinalTreatment.time_varying: Sequence[Sequence[str]] | None = None#
LongitudinalTreatment.treatment_probabilities: Any = None#
LongitudinalTreatment.weights: str | None = None#
LongitudinalTreatment.weights_estimated: bool = False#
LongitudinalTreatment.weights_type: Literal['probability'] = 'probability'#
LongitudinalTreatment.outcome: str | Sequence[str] | Mapping[str, Sequence[str]] | Repeated#
LongitudinalTreatment.treatment: str | Sequence[str]#
LongitudinalTreatment.baseline: Sequence[str]#