cleverly.TimeToEvent#
- class cleverly.TimeToEvent(time: str, event: str, treatment: str, baseline: Sequence[str], grid: Sequence[float] | None = None, causes: Mapping[int, str] | None = None, cluster: str | None = None, weights: str | None = None, weights_type: Literal['probability'] = 'probability', weights_estimated: bool = False, time_varying: None = None, continuous_treatment: bool = False, treatment_probabilities: Any = None, treatment_support: Any = None, dose_atoms: Sequence[float] = ())[source]#
Declare a baseline treatment with one follow-up time and one event code per unit.
The data hold one row per unit. The time is binned onto a grid \(0 = g_0 < g_1 < \dots < g_K\), node \(k\) covers \((g_{k-1}, g_k]\), and the treatment is one decision held over every node.
cleverly.longitudinal.LongitudinalData.from_time_to_event()states the binning rules and the refusals. The estimand is a risk or a cumulative incidence at the grid times, as for a survivalLongitudinalTreatment. At a grid time before which no follower of a regimen had the event, the risk is zero and reports no interval (status"constant_node_plugin").- Parameters:
- time
str The follow-up time column. Every time is a positive finite number.
- event
str The event-code column:
0for censored, and a positive integer per cause.- treatment
str The baseline treatment column.
- baselinesequence
ofstr Covariates measured before the treatment. The list names at least one column.
- gridsequence
offloatorNone The grid times, which are the visit times.
Noneneeds integer times and uses \(g_k = k\) up to the largest event time. The fit costs \(K(K+1)/2\) sequential regressions per regimen and cause, so a default grid on day-level times can hold thousands of nodes.- causes
mappingofinttostrorNone The label of each nonzero event code.
Nonereads codes{0, 1}as one event and any other codes as competing causes labelledstr(code).- 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.
- time_varying
None Not accepted. One row per unit holds no covariate measured after baseline, so any other value raises
CapabilityErrorwith codeapi_redirection.- continuous_treatmentbool
Whether the treatment is a continuous dose. A regimen is then a modified treatment policy at baseline.
- treatment_probabilities
mappingofleveltostr,orNone The known baseline treatment mechanism (a tuple of
(level, column)pairs is also accepted) of a randomized design: each treatment level mapped to the column that holds \(P(A = \text{level} \mid W)\). The fit then divides by these probabilities and fits no treatment learner. A design names columns, so the array forms ofcleverly.longitudinal.LTMLE.fit()are refused here.- treatment_support
SupportorNone The declared conditional support of a continuous treatment.
- dose_atomssequence
offloat The doses of a continuous treatment with a recorded point mass.
- time
- Attributes:
See also
LongitudinalTreatmentThe wide layout, which also takes post-baseline covariates.
CausalStudyWhat a design is handed to along with the data.
cleverly.longitudinal.LongitudinalData.from_time_to_eventThe container it builds.
Examples
>>> from cleverly import TimeToEvent >>> design = TimeToEvent( ... time="ftime", event="ftype", treatment="arm", baseline=["age"], grid=[30, 60, 90] ... ) >>> design.grid (30.0, 60.0, 90.0)
Methods#
Attributes#
- TimeToEvent.outcome#
The event-code column, which the identified functional names as the outcome.