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:
regimenstr

The regimen’s label.

causestr or None

The cause the fit is for under competing events, None otherwise.

horizonint

The last node the fit reads: the horizon of a cumulative-risk fit, the final node of an end-of-study outcome.

repeatint

The cross-fitting repeat the weights come from, counted from one.

n_repeatsint

How many repeats the result holds.

timestuple of int

The nodes, from one.

node_kindstuple of str

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.

usedndarray of shape (n, T)

The weight the fit used: the data’s weight times the clever covariate, nan for a unit that is not a follower at that node.

followedndarray of bool, shape (n, T)

Which units were followers, the rows the fit’s fluctuation read.

cumulative_unboundedndarray of shape (n, T)

The cumulative probability of following the regimen to the node, before the bounds.

cumulativendarray of shape (n, T)

The same after the bounds, which is what the fit divided by.

boundstuple of float

The g_bounds limits 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 horizon is one of several; otherwise it is the final time point of an end-of-study outcome.

Methods#

NodeWeights.to_frame(backend: str | None = None) → Any[source]#

Return one row per unit and node.

Parameters:
backend{“pandas”, “polars”, “pyarrow”} or None, default=None

Dataframe backend to return. None uses pandas when installed, then the first available backend.

Returns:
dataframe

The columns row, time, node_kind, followed, weight_used, cumulative_unbounded and cumulative, with the regimen, cause, horizon and repeat on every row.

Attributes#

NodeWeights.cross_fitted: bool = False#
NodeWeights.effective_n#

Kish effective sample size of the used weights at each node.

NodeWeights.reports_curve: bool = False#
NodeWeights.share_beyond_bounds#

The share of followers at each node whose cumulative probability the bounds moved.

NodeWeights.regimen: str#
NodeWeights.cause: str | None#
NodeWeights.horizon: int#
NodeWeights.repeat: int#
NodeWeights.n_repeats: int#
NodeWeights.times: tuple[int, ...]#
NodeWeights.node_kinds: tuple[str, ...]#
NodeWeights.used: NDArray[float64]#
NodeWeights.followed: NDArray[bool]#
NodeWeights.cumulative_unbounded: NDArray[float64]#
NodeWeights.cumulative: NDArray[float64]#
NodeWeights.bounds: tuple[float, float]#
NodeWeights.unit_weights: bool#