View source: R/pmcalibration.R
pmcalibration | R Documentation |
Assess calibration of clinical prediction models (agreement between predicted and observed probabilities) via different smooths. Binary and time-to-event outcomes are supported.
pmcalibration(
y,
p,
smooth = c("none", "ns", "bs", "rcs", "gam", "lowess", "loess"),
time = NULL,
ci = c("sim", "boot", "pw", "none"),
n = 1000,
transf = NULL,
eval = 100,
...
)
y |
a binary or a right-censored time-to-event outcome. Latter must be an object created via |
p |
predicted probabilities from a clinical prediction model. For a time-to-event object |
smooth |
what smooth to use. Available options:
'rcs', 'ns', 'bs', and 'none' are fit via |
time |
what follow up time do the predicted probabilities correspond to? Only used if |
ci |
what kind of confidence intervals to compute?
Calibration metrics are calculated using each simulation or boot sample. For both options percentile confidence intervals are returned. |
n |
number of simulations or bootstrap resamples |
transf |
transformation to be applied to |
eval |
number of points (equally spaced between |
... |
additional arguments for particular smooths. For ci = 'boot' the user is able to run samples in parallel (using the |
a pmcalibration
object containing calibration metrics and values for plotting
Austin P. C., Steyerberg E. W. (2019) The Integrated Calibration Index (ICI) and related metrics for quantifying the calibration of logistic regression models. Statistics in Medicine. 38, pp. 1–15. https://doi.org/10.1002/sim.8281
Van Calster, B., Nieboer, D., Vergouwe, Y., De Cock, B., Pencina M., Steyerberg E.W. (2016). A calibration hierarchy for risk models was defined: from utopia to empirical data. Journal of Clinical Epidemiology, 74, pp. 167-176. https://doi.org/10.1016/j.jclinepi.2015.12.005
Austin, P. C., Harrell Jr, F. E., & van Klaveren, D. (2020). Graphical calibration curves and the integrated calibration index (ICI) for survival models. Statistics in Medicine, 39(21), 2714-2742. https://doi.org/10.1002/sim.8570
# binary outcome -------------------------------------
library(pmcalibration)
# simulate some data
n <- 500
dat <- sim_dat(N = n, a1 = .5, a3 = .2)
head(dat)
# predictions
p <- with(dat, invlogit(.5 + x1 + x2 + x1*x2*.1))
# fit calibration curve
cal <- pmcalibration(y = dat$y, p = p, smooth = "gam", k = 20, ci = "pw")
summary(cal)
plot(cal)
# time to event outcome -------------------------------------
library(pmcalibration)
if (requireNamespace("survival", quietly = TRUE)){
library(survival)
data('transplant', package="survival")
transplant <- na.omit(transplant)
transplant = subset(transplant, futime > 0)
transplant$ltx <- as.numeric(transplant$event == "ltx")
# get predictions from coxph model at time = 100
# note that as we are fitting and evaluating the model on the same data
# this is internal calibration (see vignette("internal-validation", package = "pmcalibration"))
cph <- coxph(Surv(futime, ltx) ~ age + sex + abo + year, data = transplant)
time <- 100
newd <- transplant; newd$futime <- time; newd$ltx <- 1
p <- 1 - exp(-predict(cph, type = "expected", newdata=newd))
y <- with(transplant, Surv(futime, ltx))
cal <- pmcalibration(y = y, p = p, smooth = "rcs", nk=5, ci = "pw", time = time)
summary(cal)
plot(cal)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.