torchsurv.stats.ipcw

Contents

torchsurv.stats.ipcw#

Functions

get_ipcw(event, time[, new_time, checks])

Calculate the inverse probability censoring weights (IPCW).

torchsurv.stats.ipcw.get_ipcw(event: tensor, time: tensor, new_time: tensor | None = None, checks: bool = True) Tensor[source]#

Calculate the inverse probability censoring weights (IPCW).

Parameters:
  • event (torch.Tensor, boolean) – Event indicator of size n_samples (= True if event occured).

  • time (torch.Tensor, float) – Time-to-event or censoring of size n_samples.

  • new_time (torch.Tensor, float, optional) – New time at which to evaluate the IPCW. Defaults to time.

  • checks (bool) – Whether to perform input format checks. Enabling checks can help catch potential issues in the input data. Defaults to True.

Returns:

IPCW evaluated at new_time.

Return type:

torch.Tensor

Examples

>>> _ = torch.manual_seed(42)
>>> n = 5
>>> event = torch.randint(low=0, high=2, size=(n,)).bool()
>>> time = torch.randint(low=1, high=100, size=(n,)).float()
>>> new_time = torch.randint(low=1, high=100, size=(n*2,))
>>> get_ipcw(event, time) # ipcw evaluated at time
tensor([1.8750, 1.2500, 3.7500, 0.0000, 1.2500])
>>> get_ipcw(event, time, new_time) # ipcw evaluated at new_time
tensor([1.8750, 1.8750, 3.7500, 3.7500, 0.0000, 1.2500, 0.0000, 1.2500, 1.2500,
        1.2500])

Note

The inverse probability of censoring weight at time \(t\) is defined by

\[\omega(t) = 1 / \hat{D}(t),\]

where \(\hat{D}(t)\) is the Kaplan-Meier estimate of the censoring distribution, \(P(D>t)\).