cleverly.longitudinal.NodeWeights#
- class cleverly.longitudinal.NodeWeights(regimen: str, cause: str | None, horizon: int, repeat: int, n_repeats: int, times: tuple[int, ...], node_kinds: tuple[str, ...], used: NDArray[float64], followed: NDArray[bool], cumulative_unbounded: NDArray[float64], cumulative: NDArray[float64], bounds: tuple[float, float], unit_weights: bool, cross_fitted: bool = False, reports_curve: bool = False)[source]#
The weights one fitted regimen used at each node, one row per unit.
- Parameters:
- regimen
str The regimen’s label.
- cause
strorNone The cause the fit is for under competing events,
Noneotherwise.- horizon
int The last node the fit reads: the horizon of a cumulative-risk fit, the final node of an end-of-study outcome.
- repeat
int The cross-fitting repeat the weights come from, counted from one.
- n_repeats
int How many repeats the result holds.
- times
tupleofint The nodes, from one.
- node_kinds
tupleofstr What decided the arm at each node:
"label","rule","policy","tilt","mtp", or"held"."held"marks a later node of a held design whose regimen declares a one-node rule, policy or modified treatment policy; a static arm reports"label"there.- used
ndarrayofshape(n,T) The weight the fit used: the data’s weight times the clever covariate,
nanfor a unit that is not a follower at that node.- followed
ndarrayofbool,shape(n,T) Which units were followers, the rows the fit’s fluctuation read.
- cumulative_unbounded
ndarrayofshape(n,T) The cumulative probability of following the regimen to the node, before the bounds.
- cumulative
ndarrayofshape(n,T) The same after the bounds, which is what the fit divided by.
- bounds
tupleoffloat The
g_boundslimits on the cumulative probability.- unit_weightsbool
Whether every observation weight was one, so that
1 / bounds[0]is the largest weight a node can carry at a static or rule node.- cross_fittedbool
Whether the probabilities are out-of-fold predictions; in-sample otherwise.
- reports_curvebool
Whether the fit reports a curve over horizons, so that
horizonis one of several; otherwise it is the final time point of an end-of-study outcome.
- regimen
Methods#
- NodeWeights.to_frame(backend: str | None = None) Any[source]#
Return one row per unit and node.
- Parameters:
- backend{“pandas”, “polars”, “pyarrow”}
orNone, default=None Dataframe backend to return.
Noneuses pandas when installed, then the first available backend.
- backend{“pandas”, “polars”, “pyarrow”}
- Returns:
dataframeThe columns
row,time,node_kind,followed,weight_used,cumulative_unboundedandcumulative, with the regimen, cause, horizon and repeat on every row.
Attributes#
- NodeWeights.effective_n#
Kish effective sample size of the used weights at each node.
The share of followers at each node whose cumulative probability the bounds moved.
- NodeWeights.used: NDArray[float64]#
- NodeWeights.cumulative_unbounded: NDArray[float64]#
- NodeWeights.cumulative: NDArray[float64]#