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:
- outcome
str, sequenceofstr,mappingofstrtosequenceofstr,orRepeated End-of-study outcome, survival event nodes, competing-risk event nodes, or a
Repeatedoutcome measured at every node.- treatment
stror sequenceofstr 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 fromtime_varying, else it is one.- baselinesequence
ofstr Covariates observed before the first treatment. The list names at least one column.
- time_varyingsequence
ofsequenceofstrorNone Covariate blocks observed before each treatment node.
- censoringsequence
ofstrorNone Observation indicators in time order. One means observed.
- cluster
strorNone Independent-cluster identifier.
- weights
strorNone 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
ofstr,ormappingofstrtoSupportorNone 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, ascleverly.longitudinal.LTMLE.fit()takes it.- dose_atoms
mappingofstrtosequenceoffloat,orNone The doses of each continuous node with a recorded point mass, as
cleverly.longitudinal.LTMLE.fit()takes them.- treatment_probabilities
mappingorNone 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_probabilities
mappingorNone 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.
- outcome
See also
PointTreatmentThe same declaration for treatment given once.
TimeToEventA baseline treatment with one time and one event column.
CausalStudyWhat a design is handed to along with the data.
cleverly.datasets.make_longitudinalA 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_varyingis 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',))