get_cc | R Documentation |
pmcalibration
objectExtract plot data from pmcalibration
object
get_cc(x, conf_level = 0.95)
x |
|
conf_level |
width of the confidence interval (0.95 gives 95% CI). Ignored if call to |
data frame for plotting with 4 columns
p
- values for the x-axis (predicted probabilities - note these are *not* from your data and are only used for plotting)
p_c
- probability implied by the calibration curve given p
lower
and upper
- bounds of the confidence interval
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))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.