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

cenreg.model.copula_graphic.estimate(observed_times: ndarray, uncensored: ndarray, copula, weights: ndarray | None = 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.nonparametric module

cenreg.model.nonparametric.empirical_cdf_estimator(y: ndarray, weights: ndarray | None = None, y_min: float | None = None, y_max: float | None = None) CumulativeDist

Compute CDF based on y and weight. The observed values y are weighted by weight.

Parameters:
  • y (np.ndarray) – One-dimensional ndarray containing observed values.

  • weights (np.ndarray | None) – One-dimensional ndarray containing non-negative weight for each value in y. If None, all weights are set to 1.0.

  • y_min (float | None) – The lower bound for the CDF. If None, it is set to the minimum observed value.

  • y_max (float | None) – The upper bound for the CDF. If None, it is set to the maximum observed value.

Returns:

dist – Empirical CDF object.

Return type:

CumulativeDist

cenreg.model.nonparametric.kaplan_meier_estimator(observed_times: ndarray, uncensored: ndarray, weights: ndarray | None = None, y_min: float | None = None, y_max: float | None = None) CumulativeDist

Compute Kaplan-Meier estimator.

Parameters:
  • observed_times (np.ndarray) – Observed times (both censored and uncensored).

  • uncensored (np.ndarray) – Indicator for uncensored data (1: uncensored, 0: censored).

  • weights (np.ndarray | None) – Weights for each data point.

  • y_min (float | None) – Minimum value for the EmpiricalCDF. If None, y_min is set to 0.0.

  • y_max (float | None) – Maximum value for the EmpiricalCDF. If None, y_max is set to observed_times.max().

Returns:

dist – Cumulative distribution function.

Return type:

CumulativeDist

cenreg.model.nonparametric.li_watkins_yu_estimator(lb: ndarray, ub: ndarray, y_min: float | None = None, y_max: float | None = None, weights: ndarray | None = None, eps: float = 1e-08, max_iter: int = 100)

Li-Watkins-Yu estimator for interval-censored data.

Parameters:
  • lb (np.ndarray) – Lower bounds of observed intervals.

  • ub (np.ndarray) – Upper bounds of observed intervals.

  • y_min (float | None) – Minimum value for the CDF.

  • y_max (float | None) – Maximum value for the CDF.

  • weights (np.ndarray | None) – Weights for each data point.

  • eps (float) – Convergence threshold.

  • max_iter (int) – Maximum number of iterations.

Returns:

cdf – Cumulative distribution function object.

Return type:

cenreg.distribution.cdf.CumulativeDist

cenreg.model.nonparametric.turnbull_estimator(lb: ndarray, ub: ndarray, y_min: float | None = None, y_max: float | None = None, weights: ndarray | None = None, eps: float = 1e-08, max_iter: int = 100)

Turnbull estimator for interval-censored data.

Parameters:
  • lb (np.ndarray) – Lower bounds of observed intervals.

  • ub (np.ndarray) – Upper bounds of observed intervals.

  • y_min (float | None) – Minimum value for the CDF.

  • y_max (float | None) – Maximum value for the CDF.

  • weights (np.ndarray | None) – Weights for each data point.

  • eps (float) – Convergence threshold.

  • max_iter (int) – Maximum number of iterations.

Returns:

cdf – Cumulative distribution function object.

Return type:

cenreg.distribution.cdf.CumulativeDist

cenreg.model.nonparametric.zheng_klein_estimator(observed_times: ndarray, uncensored: ndarray, copula, weights: ndarray | None = None, y_min: float | None = None, y_max: float | None = None) CumulativeDist

Compute copula-graphic estimator proposed by Zheng and Klein. This method receives any copula.

Parameters:
  • observed_times (np.ndarray) – Observed times (both censored and uncensored).

  • uncensored (np.ndarray) – Indicator for uncensored data (1: uncensored, 0: censored).

  • copula (object) – Copula function.

  • weights (np.ndarray | None) – Weights for each data point.

  • y_min (float | None) – Minimum value for the EmpiricalCDF. If None, y_min is set to 0.0.

  • y_max (float | None) – Maximum value for the EmpiricalCDF. If None, y_max is set to observed_times.max().

Returns:

dist – Cumulative distribution function.

Return type:

CumulativeDist

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.