discotime.utils.estimators module

class discotime.utils.estimators.AalenJohansen(time: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], event: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], n_causes: int | int64 | None = None)[source]

Bases: object

Obtain cumulative incidence curves with the Aalen-Johansen method.

Parameters:
  • time – event times

  • event – event indicator (0/1/../c) with 0=censored

  • n_causes – how many causes should be included? If None (the default) then all observed causes are include.

class discotime.utils.estimators.KaplanMeier(time: Iterable[int | int64 | float | float64], event: Iterable[int | int64])[source]

Bases: object

Simple implementation of the Kaplan-Meier estimator.

Parameters:
  • time – event times.

  • event – event indicator (0/1) where 0 is censoring.

Example

>>> km = KaplanMeier(time=[0, 1.5, 1.3, 3], event=[0, 1, 0, 0])
>>> km(0)
array([1.])
>>> km([0, 1.0, 1.1, 1.5])
array([1. , 1. , 1. , 0.5])
percentile(p: ~collections.abc.Iterable[int | ~numpy.int64 | float | ~numpy.float64], dtype=<class 'numpy.float64'>) ndarray[Any, dtype[float64]][source]

Obtain approximate timepoint t such that P(t) = p.

The stepwise Kaplan-Meier estimator is piecewise linearly interpolated such that unique timepoints can be obtained.

discotime.utils.estimators.interpolate2d(x: Tensor, xp: Tensor, yp: Tensor)[source]

Perform stepwise linear interpolation of a discrete function.

_xp_ and _yp_ are tensors of values used to approximate f: y = f(x). This functions uses interpolation to find the value of new points x.

Parameters:
  • x (torch.Tensor) – an 1D tensor real values.

  • xp (torch.Tensor) – an 1D tensor of real values.

  • yp (torch.Tensor) – an ND tensor of real values. The length of yp along the second axis (dim=1) must have the same length as xp.