cenreg.model package — cenreg 0.0.4 documentation

# cenreg.model package

## Submodules

## cenreg.model.F2cjd_np module

cenreg.model.F2cjd_np.convert(F_pred: ndarray, copula, w: List[int], num_risks: int, k: int, list_K: List[int]) → ndarray

  Convert F_pred into jd_pred.

  Parameters:

    - F_pred (np.ndarray of shape [batch_size, num_risks, 3]) – The three elements in the last axis are the lower bound, the current value, and the upper bound.

    - copula (function)

    - w (list of weight parameters (between 0 and 1))

    - num_risks (int) – The number of risks.

    - k (int) – The index of the risk.

    - list_K (list of int) – The list of indices of the risks.

  Returns:

    jd_pred

  Return type:

    np.ndarray of shape [batch_size, num_risks]

## cenreg.model.cjd2F_np module

cenreg.model.cjd2F_np.cjd2surv(jd_pred: ndarray, algorithm: str = 'integral') → ndarray

  Estimate the survival function from the CJD representation.

  Parameters:

    - jd_pred (np.ndarray of shape [batch_size, num_risks, num_bin_predictions])

    - algorithm (str, optional) – Algorithm to use for estimation. Currently only “integral” is supported.

  Returns:

    F_pred – np.ndarray of shape [batch_size, num_risks, num_bin_predictions+1]

  Return type:

    estimated CDF.

## cenreg.model.copula_graphic module

class cenreg.model.copula_graphic.CopulaGraphicDistribution(observed_times: ndarray, uncensored: ndarray, copula, weights: ndarray | None = None)

  Bases: `object`

  Distribution class of Copula-Graphic estimator.

  Notes

  The first observation time must be strictly greater than 0. At least one data point is uncensored. CDF values can be strictly less than 1.0 after the last uncensored data point. Survival rates can be strictly greater than 0.0 after the last uncensored data point. Inverse CDF values may not be correct for large quantiles (due to the above notes).

  average_cdf(t: ndarray)
  cdf(t: ndarray)

    Compute cumulative distribution function.

    Parameters:

      t (ndarray (float)) – ndarray of shape [batch_size] containing time points.

    Returns:

      cumulative probability – ndarray of shape [batch_size] containing cumulative probability of event occurrence.

    Return type:

      ndarray (float)

  icdf(quantiles: ndarray)

    Compute cumulative distribution function.

    Parameters:

      quantiles (ndarray (float)) – ndarray of shape [batch_size] containing quantiles.

    Returns:

      cumulative probability – ndarray of shape [batch_size] containing cumulative probability of event occurrence.

    Return type:

      ndarray (float)

  survival_function(t: ndarray)

    Compute survival function.

    Parameters:

      t (ndarray (float)) – ndarray of shape [batch_size] containing time points.

    Returns:

      survival_rates – ndarray of shape [batch_size] containing survival rates.

    Return type:

      ndarray (float)

cenreg.model.copula_graphic.estimate(observed_times: ndarray, uncensored: ndarray, copula, weights: ndarray = None)

  Copula-Graphic estimator. This method receives any copula.

  Parameters:

    - observed_times (ndarray (float)) – One-dimensional ndarray containing observed times.

    - uncensored (ndarray (bool)) – One-dimensional ndarray containing censored (False) or uncensored (True).

    - copula (object) – Copula function.

    - weights (ndarray (float) or None) – One-dimensional ndarray containing weights. If None, all weights are set to 1.

  Returns:

    - times (ndarray (float)) – One-dimensional ndarray containing time points.

    - values (ndarray (float)) – One-dimensional ndarray containing survival rates.

## cenreg.model.copula_np module

class cenreg.model.copula_np.FrankCopula(theta: float)

  Bases: `object`

  Frank copula implemented with numpy.

  cdf(u: ndarray) → ndarray

    Compute cumulative distribution function.

    Parameters:

      u (ndarray (float)) – ndarray of shape [batch_size, 2]. Each element should be in [0, 1].

    Returns:

      cumulative probability – ndarray of shape [batch_size].

    Return type:

      ndarray (float)

class cenreg.model.copula_np.IndependenceCopula

  Bases: `object`

  Independence copula implemented with numpy.

  cdf(u: ndarray) → ndarray

    Compute cumulative distribution function.

    Parameters:

      u (ndarray (float)) – ndarray of shape [batch_size, 2]. Each element should be in [0, 1].

    Returns:

      probability – ndarray of shape [batch_size].

    Return type:

      ndarray (float)

class cenreg.model.copula_np.SurvivalCopula(copula)

  Bases: `object`

  Survival copula implemented with pytorch.

  cdf(u: ndarray) → ndarray

cenreg.model.copula_np.create(name: str, theta: float)

## cenreg.model.kaplan_meier module

class cenreg.model.kaplan_meier.KaplanMeierDistribution

  Bases: `object`

  Distribution class of Kaplan-Meier estimator. This class does not use any interpolation.

  Notes

  At least one data point must be uncensored. CDF values can be strictly less than 1.0 after the last uncensored data point. Survival rates can be strictly greater than 0.0 after the last uncensored data point. Inverse CDF values may not be correct for large quantiles (due to the above notes). While the original Kaplan-Meier estimator is defined for non-negative times, this implementation can handle negative times.

  average_cdf(t: ndarray)

    Compute average cumulative distribution function.

    Parameters:

      t (ndarray (float)) – ndarray of shape [batch_size] containing time points.

    Returns:

      average cumulative probability – ndarray of shape [batch_size] containing average cumulative probability of event occurrence.

    Return type:

      ndarray (float)

  cdf(t: ndarray, add_edges: bool = False)

    Compute cumulative distribution function.

    Parameters:

      - t (ndarray (float)) – ndarray of shape [num_bins] containing time points.

      - add_edges (bool) – If True, add 0.0 at the start time and 1.0 at the last observed time.

    Returns:

      cumulative probability – ndarray of shape [num_bins] containing cumulative probability of event occurrence.

    Return type:

      ndarray (float)

  fit(observed_times: ndarray, uncensored: ndarray, weights: ndarray | None = None, alpha: float | None = None)
  icdf(quantiles: ndarray)

    Compute cumulative distribution function.

    Parameters:

      quantiles (ndarray (float)) – ndarray of shape [batch_size] containing quantiles.

    Returns:

      cumulative probability – ndarray of shape [batch_size] containing cumulative probability of event occurrence.

    Return type:

      ndarray (float)

  survival_function(t: ndarray)

    Compute survival function.

    Parameters:

      t (ndarray (float)) – Survival rates are computed for values t. t must be one or two-dimensional ndarray.

    Returns:

      survival_rates – ndarray of the same shape as t containing survival rates.

    Return type:

      ndarray (float)

cenreg.model.kaplan_meier.createCdfLinear(observed_times: ndarray, uncensored: ndarray, bins: ndarray)

  Create CdfLinear object from Kaplan-Meier estimator.

  Parameters:

    - observed_times (ndarray (float)) – One-dimensional ndarray containing observed times.

    - uncensored (ndarray (bool)) – One-dimensional ndarray containing censored (False) or uncensored (True).

    - bins (ndarray (float)) – One-dimensional sorted ndarray containing time bins. The first element must be 0.0. The last element must be larger than maximum time of observed_times.

  Return type:

    CdfLinear object

cenreg.model.kaplan_meier.createQuantilesLinear(observed_times: ndarray, uncensored: ndarray, qk_levels: ndarray, max_time: float)

  Create QuantilesLinear object from Kaplan-Meier estimator.

  Parameters:

    - observed_times (ndarray (float)) – One-dimensional ndarray containing observed times.

    - uncensored (ndarray (bool)) – One-dimensional ndarray containing censored (False) or uncensored (True).

    - qk_levels (ndarray (float)) – One-dimensional ndarray containing quantile levels.

    - max_time (float) – max_time must be larger than maximum time of observed_times.

  Return type:

    QuantilesLinear object

## Module contents

cenreg.model.cjd2surv(jd_pred: ndarray, algorithm: str = 'integral') → ndarray

  Estimate the survival function from the CJD representation.

  Parameters:

    - jd_pred (np.ndarray of shape [batch_size, num_risks, num_bin_predictions])

    - algorithm (str, optional) – Algorithm to use for estimation. Currently only “integral” is supported.

  Returns:

    F_pred – np.ndarray of shape [batch_size, num_risks, num_bin_predictions+1]

  Return type:

    estimated CDF.