library(pmcalibration)
# simulate some data with a binary outcome
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")
cplot <- get_cc(cal, conf_level = .95)
head(cplot)
if (requireNamespace("ggplot2", quietly = TRUE)){
library(ggplot2)
ggplot(cplot, aes(x = p, y = p_c, ymin=lower, ymax=upper)) +
geom_abline(intercept = 0, slope = 1, lty=2) +
geom_line() +
geom_ribbon(alpha = 1/4) +
lims(x=c(0,1), y=c(0,1))
}
Run the code above in your browser using DataLab