Metrics

survivors.metrics.DESCEND_METRICS = ['ibs', 'IBS', 'aic', 'AIC', 'bic', 'BIC', 'KL', 'BAL_IBS', 'IBS_WW', 'BAL_IBS_WW', 'IBS_REMAIN', 'BAL_IBS_REMAIN']

list: Metrics with decreasing quality improvement

survivors.metrics.METRIC_DICT = {'AUPRC': <function <lambda>>, 'AUPRC_by_obs': <function <lambda>>, 'BAL_AUPRC': <function <lambda>>, 'BAL_IBS': <function <lambda>>, 'BAL_IBS_REMAIN': <function <lambda>>, 'BAL_IBS_WW': <function <lambda>>, 'CENS_AUPRC': <function <lambda>>, 'CI': <function <lambda>>, 'CI_CENS': <function <lambda>>, 'EVENT_AUPRC': <function <lambda>>, 'IAUC': <function <lambda>>, 'IAUC_TI': <function <lambda>>, 'IAUC_WW': <function <lambda>>, 'IAUC_WW_TI': <function <lambda>>, 'IBS': <function <lambda>>, 'IBS_REMAIN': <function <lambda>>, 'IBS_WW': <function <lambda>>, 'KL': <function <lambda>>, 'LOGLIKELIHOOD': <function <lambda>>}

dict: Available metrics in library and its realization

survivors.metrics.bal_ibs(survival_train, survival_test, estimate, times, axis=-1)

IBS with equal impact of each event type

survivors.metrics.bal_ibs_WW(survival_train, survival_test, estimate, times, axis=-1)

IBS with equal impact of each event type and partial observation

survivors.metrics.bal_ibs_remain(survival_train, survival_test, estimate, times, axis=-1)

IBS with equal impact of each event type and partial observation with controlled quantity

survivors.metrics.concordance_index(event_times, predicted_scores, event_observed=None)

Calculates the concordance index (C-index) for survival analysis. Previous speed: 684 ms ± 4.06 ms per loop (mean ± std. dev. of 7 runs, 1 loop each). Current speed: 22.7 ms ± 128 µs per loop (mean ± std. dev. of 7 runs, 10 loops each). Speed has increased by ~30 times

Parameters

event_times: Array of true event times. predicted_scores: Array of predicted event times. event_observed: Array of event indicators (1 if event occurred, 0 if censored).

Returns

The concordance index: float

Examples

from survivors.metrics import concordance_index
concordance_index(np.array([10, 20, 30, 40]),
                  np.array([20, 19, 29, 39]),
                  np.array([1, 0, 1, 0]))
survivors.metrics.get_hazard_func(ddeath, cdeath, bins=None)

Build Nelson-Aalen Estimate of Hazard function

Parameters

ddeatharray-like

Times of occurred events

cdeatharray-like

Indicate of occurred events (Censoring flag)

binsarray-like, optional

Points of hazard function. The default is None.

Returns

NelsonAalenFitter or array
If bins is None return Nelson-Aalen model,

else return values of HF.

survivors.metrics.get_survival_func(ddeath, cdeath, bins=None)

Build Kaplan-Meier Estimate of survival function

Parameters

ddeatharray-like

Times of occurred events

cdeatharray-like

Indicate of occurred events (Censoring flag)

binsarray-like, optional

Points of survival function. The default is None.

Returns

KaplanMeierFitter or array
If bins is None return kaplan-meier model,

else return values of SF.

survivors.metrics.iauc(survival_train, survival_test, estimate, times, tied_tol=1e-08, no_wei=False, time_int=False)
Modified integrated AUC (cumulative_dynamic_auc)

from scikit-survival (reduce complexity)

Parameters

survival_trainstructured array, shape = (n_train_samples,)

Survival times for training data to estimate the censoring distribution from. A structured array containing the binary event indicator as first field, and time of event or time of censoring as second field.

survival_teststructured array, shape = (n_samples,)

Survival times of test data. A structured array containing the binary event indicator as first field, and time of event or time of censoring as second field.

estimatearray-like, shape = (n_samples, n_times)

Estimated risk of experiencing an event for test data at times. The i-th column must contain the estimated probability of remaining event-free up to the i-th time point.

timesarray-like, shape = (n_times,)

The time points for which to estimate the Brier score.

tied_tolfloat, optional, default: 1e-8

The tolerance value for considering ties. If the absolute difference between risk scores is smaller or equal than tied_tol, risk scores are considered tied.

Returns

mean_aucfloat

Summary measure referring to the mean cumulative/dynamic AUC over the specified time range (times[0], times[-1]).

survivors.metrics.iauc_TI(s_tr, s_tst, est, times, tied_tol=1e-08)

IAUC with integration by time (instead of S(t))

survivors.metrics.iauc_WW(s_tr, s_tst, est, times, tied_tol=1e-08)

IAUC without weighting for each observation

survivors.metrics.iauc_WW_TI(s_tr, s_tst, est, times, tied_tol=1e-08)

IAUC with equal weight for each observation and integration by time

survivors.metrics.ibs(survival_train, survival_test, estimate, times, axis=-1)

Modified integrated brier score from scikit-survival (add axis) Modification: with axis = 0 count ibs for each observation

Parameters

survival_trainstructured array, shape = (n_train_samples,)

Survival times for training data to estimate the censoring distribution from. A structured array containing the binary event indicator as first field, and time of event or time of censoring as second field.

survival_teststructured array, shape = (n_samples,)

Survival times of test data. A structured array containing the binary event indicator as first field, and time of event or time of censoring as second field.

estimatearray-like, shape = (n_samples, n_times)

Estimated risk of experiencing an event for test data at times. The i-th column must contain the estimated probability of remaining event-free up to the i-th time point.

timesarray-like, shape = (n_times,)

The time points for which to estimate the Brier score.

axisint, optional

With axis = 1 count bs for each time from times With axis = 0 count ibs for each observation. With axis = -1 count mean ibs. The default is -1.

Returns

ibs_valuefloat or array-like or None
if axis = 0 return array of ibs for each observation

axis = 1 return array of bs for each time from times axis = -1 return float

else

None

survivors.metrics.ibs_WW(survival_train, survival_test, estimate, times, axis=-1)

IBS with equal impact of partial observation

survivors.metrics.ibs_remain(survival_train, survival_test, estimate, times, axis=-1)

IBS with equal impact of partial observation with controlled quantity

survivors.metrics.ipa(survival_train, survival_test, estimate, times, axis=-1)

Index of Prediction Accuracy: General R^2 for binary outcome and right censored time to event (survival) outcome also with competing risks.

Parameters

survival_trainstructured array, shape = (n_train_samples,)

Survival times for training data to estimate the censoring distribution from. A structured array containing the binary event indicator as first field, and time of event or time of censoring as second field.

survival_teststructured array, shape = (n_samples,)

Survival times of test data. A structured array containing the binary event indicator as first field, and time of event or time of censoring as second field.

estimatearray-like, shape = (n_samples, n_times)

Estimated risk of experiencing an event for test data at times. The i-th column must contain the estimated probability of remaining event-free up to the i-th time point.

timesarray-like, shape = (n_times,)

The time points for which to estimate the Brier score.

axisint, optional

With axis = 1 count ipa for each time from times With axis = 0 count ipa for each observation. With axis = -1 count mean ipa. The default is -1.

Returns

ibs_valuefloat or array-like or None
if axis = 0 return array

axis = 1 return array axis = -1 return float

else

None

survivors.metrics.kl(time, cens, sf, cumhf, bins)

Kullback-Leibler divergence in terms of survival analysis

survivors.metrics.loglikelihood(time, cens, sf, cumhf, bins)

Likelihood in terms of survival analysis (without PH)