calibration() checks predicted survival probabilities at one time against what was observed.
The subjects are split into n_bins groups at the quantiles of their predictions, and in each
group the mean prediction is set beside the Kaplan-Meier estimate at time, with its
confidence interval on the log scale. In a well-calibrated model the two are close. Bins with
no subjects are dropped, so tied predictions can give fewer rows.
Arguments
- response
A right-censored or counting-process
Surv()object.- predicted
The predicted survival probability at
timefor each subject.- time
The time at which the predictions are checked.
- n_bins
The number of groups, at least 2. The default is 10.
- conf_level
The confidence level of the observed interval. The default is
0.95.
Value
A data frame with one row per bin: bin, n, predicted (the mean prediction),
observed, observed_lower, and observed_upper.
Examples
lung <- data.frame(
time = c(306, 455, 1010, 210, 883, 1022, 310, 361, 218, 166, 170, 654),
status = c(2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2),
age = c(74, 68, 56, 57, 60, 74, 68, 71, 53, 61, 57, 68)
)
fit <- cox_ph(Surv(time, status) ~ age, data = lung)
p <- predict(fit, newdata = lung, type = "survival", times = 300)
calibration(Surv(lung$time, lung$status), predicted = p$estimate, time = 300, n_bins = 3)
#> bin n predicted observed observed_lower observed_upper
#> 1 1 4 0.6073168 0.25 0.04579076 1
#> 2 2 2 0.6509337 0.50 0.12504883 1
#> 3 3 6 0.7302373 1.00 1.00000000 1