Skip to contents

Helper function to compose a survival distribution (or cumulative hazard) from the relative risk predictions (linear predictors, lp) of a proportional hazards model (e.g. a Cox-type model).

Usage

breslow(times, status, lp_train, lp_test, eval_times = NULL, type = "surv")

Arguments

times

(numeric())
Vector of times (train set).

status

(numeric())
Vector of status indicators (train set). For each observation in the train set, this should be 0 (alive/censored) or 1 (dead).

lp_train

(numeric())
Vector of linear predictors (train set). These are the relative score predictions (\(lp = \hat{\beta}X_{train}\)) from a proportional hazards model on the train set.

lp_test

(numeric())
Vector of linear predictors (test set). These are the relative score predictions (\(lp = \hat{\beta}X_{test}\)) from a proportional hazards model on the test set.

eval_times

(numeric())
Vector of times to compute survival probabilities. If NULL (default), the unique and sorted times from the train set will be used, otherwise the unique and sorted eval_times.

type

(character())
Type of prediction estimates. Default is surv which returns the survival probabilities \(S_i(t)\) for each test observation \(i\). If cumhaz, the function returns the estimated cumulative hazards \(H_i(t)\).

Value

a matrix (obs x times). Number of columns is equal to eval_times and number of rows is equal to the number of test observations (i.e. the length of the lp_test vector). Depending on the type argument, the matrix can have either survival probabilities (0-1) or cumulative hazard estimates (0-Inf).

Details

We estimate the survival probability of individual \(i\) (from the test set), at time point \(t\) as follows: $$S_i(t) = e^{-H_i(t)} = e^{-\hat{H}_0(t) \times e^{lp_i}}$$

where:

  • \(H_i(t)\) is the cumulative hazard function for individual \(i\)

  • \(\hat{H}_0(t)\) is Breslow's estimator for the cumulative baseline hazard. Estimation requires the training set's times and status as well the risk predictions (lp_train).

  • \(lp_i\) is the risk prediction (linear predictor) of individual \(i\) on the test set.

Breslow's approach uses a non-parametric maximum likelihood estimation of the cumulative baseline hazard function:

$$\hat{H}_0(t) = \sum_{i=1}^n{\frac{I(T_i \le t)\delta_i} {\sum\nolimits_{j \in R_i}e^{lp_j}}}$$

where:

  • \(t\) is the vector of time points (unique and sorted, from the train set)

  • \(n\) is number of events (train set)

  • \(T\) is the vector of event times (train set)

  • \(\delta\) is the status indicator (1 = event or 0 = censored)

  • \(R_i\) is the risk set (number of individuals at risk just before event \(i\))

  • \(lp_j\) is the risk prediction (linear predictor) of individual \(j\) (who is part of the risk set \(R_i\)) on the train set.

We employ constant interpolation to estimate the cumulative baseline hazards, extending from the observed unique event times to the specified evaluation times (eval_times). Any values falling outside the range of the estimated times are assigned as follows: $$\hat{H}_0(eval\_times < min(t)) = 0$$ and $$\hat{H}_0(eval\_times > max(t)) = \hat{H}_0(max(t))$$

Note that in the rare event of lp predictions being Inf or -Inf, the resulting cumulative hazard values become NaN, which we substitute with Inf (and corresponding survival probabilities take the value of \(0\)).

For similar implementations, see gbm::basehaz.gbm(), C060::basesurv() and xgboost.surv::sgb_bhaz().

References

Breslow N (1972). “Discussion of 'Regression Models and Life-Tables' by D.R. Cox.” Journal of the Royal Statistical Society: Series B, 34(2), 216-217.

Lin, Y. D (2007). “On the Breslow estimator.” Lifetime Data Analysis, 13(4), 471-480. doi:10.1007/s10985-007-9048-y .

Examples

task = tsk("rats")
part = partition(task, ratio = 0.8)

learner = lrn("surv.coxph")
learner$train(task, part$train)
p_train = learner$predict(task, part$train)
p_test = learner$predict(task, part$test)

surv = breslow(times = task$times(part$train), status = task$status(part$train),
               lp_train = p_train$lp, lp_test = p_test$lp)
head(surv)
#>      23 32        39        40        45        49        51        53
#> [1,]  1  1 0.9942569 0.9884994 0.9827474 0.9827474 0.9827474 0.9827474
#> [2,]  1  1 0.9972328 0.9944503 0.9916620 0.9916620 0.9916620 0.9916620
#> [3,]  1  1 0.9971625 0.9943096 0.9914509 0.9914509 0.9914509 0.9914509
#> [4,]  1  1 0.9971625 0.9943096 0.9914509 0.9914509 0.9914509 0.9914509
#> [5,]  1  1 0.9969409 0.9938657 0.9907852 0.9907852 0.9907852 0.9907852
#> [6,]  1  1 0.9996131 0.9992232 0.9988315 0.9988315 0.9988315 0.9988315
#>             54        55        61        62        63        64        65
#> [1,] 0.9768072 0.9708613 0.9708613 0.9708613 0.9708613 0.9647664 0.9647664
#> [2,] 0.9887737 0.9858733 0.9858733 0.9858733 0.9858733 0.9828908 0.9828908
#> [3,] 0.9884899 0.9855167 0.9855167 0.9855167 0.9855167 0.9824596 0.9824596
#> [4,] 0.9884899 0.9855167 0.9855167 0.9855167 0.9855167 0.9824596 0.9824596
#> [5,] 0.9875950 0.9843925 0.9843925 0.9843925 0.9843925 0.9811003 0.9811003
#> [6,] 0.9984248 0.9980153 0.9980153 0.9980153 0.9980153 0.9975932 0.9975932
#>             66        67        68        69        70        71        72
#> [1,] 0.9586665 0.9525531 0.9464029 0.9464029 0.9402276 0.9340419 0.9278944
#> [2,] 0.9798960 0.9768846 0.9738450 0.9738450 0.9707826 0.9677046 0.9646351
#> [3,] 0.9793901 0.9763039 0.9731889 0.9731889 0.9700509 0.9668972 0.9637524
#> [4,] 0.9793901 0.9763039 0.9731889 0.9731889 0.9700509 0.9668972 0.9637524
#> [5,] 0.9777957 0.9744738 0.9711219 0.9711219 0.9677460 0.9643540 0.9609726
#> [6,] 0.9971682 0.9967397 0.9963061 0.9963061 0.9958680 0.9954265 0.9949851
#>             73        74        75        76        77        78        79
#> [1,] 0.9154402 0.9154402 0.9089700 0.9089700 0.9022524 0.8953582 0.8884508
#> [2,] 0.9583841 0.9583841 0.9551191 0.9551191 0.9517166 0.9482109 0.9446843
#> [3,] 0.9573488 0.9573488 0.9540046 0.9540046 0.9505198 0.9469296 0.9433185
#> [4,] 0.9573488 0.9573488 0.9540046 0.9540046 0.9505198 0.9469296 0.9433185
#> [5,] 0.9540897 0.9540897 0.9504966 0.9504966 0.9467535 0.9428984 0.9390219
#> [6,] 0.9940822 0.9940822 0.9936086 0.9936086 0.9931136 0.9926020 0.9920857
#>             80        81        82        83        84        85        86
#> [1,] 0.8742574 0.8669508 0.8669508 0.8669508 0.8516968 0.8516968 0.8440066
#> [2,] 0.9373931 0.9336158 0.9336158 0.9336158 0.9256761 0.9256761 0.9216453
#> [3,] 0.9358534 0.9319866 0.9319866 0.9319866 0.9238601 0.9238601 0.9197352
#> [4,] 0.9358534 0.9319866 0.9319866 0.9319866 0.9238601 0.9238601 0.9197352
#> [5,] 0.9310119 0.9268648 0.9268648 0.9268648 0.9181537 0.9181537 0.9137343
#> [6,] 0.9910130 0.9904544 0.9904544 0.9904544 0.9892739 0.9892739 0.9886713
#>             87        88        89        90        91        92        93
#> [1,] 0.8440066 0.8360258 0.8280218 0.8280218 0.8280218 0.8191580 0.8191580
#> [2,] 0.9216453 0.9174421 0.9132057 0.9132057 0.9132057 0.9084894 0.9084894
#> [3,] 0.9197352 0.9154343 0.9110999 0.9110999 0.9110999 0.9062751 0.9062751
#> [4,] 0.9197352 0.9154343 0.9110999 0.9110999 0.9110999 0.9062751 0.9062751
#> [5,] 0.9137343 0.9091280 0.9044876 0.9044876 0.9044876 0.8993242 0.8993242
#> [6,] 0.9886713 0.9880405 0.9874021 0.9874021 0.9874021 0.9866885 0.9866885
#>             94        95        96        97        98        99       100
#> [1,] 0.8098601 0.8098601 0.7901883 0.7901883 0.7901883 0.7901883 0.7901883
#> [2,] 0.9035135 0.9035135 0.8928872 0.8928872 0.8928872 0.8928872 0.8928872
#> [3,] 0.9011855 0.9011855 0.8903188 0.8903188 0.8903188 0.8903188 0.8903188
#> [4,] 0.9011855 0.9011855 0.8903188 0.8903188 0.8903188 0.8903188 0.8903188
#> [5,] 0.8938797 0.8938797 0.8822633 0.8822633 0.8822633 0.8822633 0.8822633
#> [6,] 0.9859321 0.9859321 0.9843047 0.9843047 0.9843047 0.9843047 0.9843047
#>            101       102       103       104
#> [1,] 0.7798095 0.7591196 0.7270081 0.7153434
#> [2,] 0.8872254 0.8758210 0.8577967 0.8511473
#> [3,] 0.8845302 0.8728733 0.8544577 0.8476664
#> [4,] 0.8845302 0.8728733 0.8544577 0.8476664
#> [5,] 0.8760798 0.8636375 0.8440075 0.8367767
#> [6,] 0.9834308 0.9816558 0.9788096 0.9777466