get_cc {pmcalibration} | R Documentation |
Extract plot data from pmcalibration
object
Description
Extract plot data from pmcalibration
object
Usage
get_cc(x, conf_level = 0.95)
Arguments
x |
|
conf_level |
width of the confidence interval (0.95 gives 95% CI). Ignored if call to |
Value
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 givenp
lower
andupper
- bounds of the confidence interval
Examples
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))
}
[Package pmcalibration version 0.1.0 Index]