cenreg.model package

Submodules

cenreg.model.copula module

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.jd2marginal_np module

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, boundaries: 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).

  • boundaries (ndarray (float)) – One-dimensional sorted ndarray containing time boundaries. 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.