get_cc: Extract plot data from 'pmcalibration' object

get_ccR Documentation

Extract plot data from pmcalibration object

Description

Extract plot data from pmcalibration object

Usage

get_cc(x, conf_level = 0.95)

Arguments

x

pmcalibration object

conf_level

width of the confidence interval (0.95 gives 95% CI). Ignored if call to pmcalibration didn't request confidence intervals

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 given p

  • lower and upper - 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))
}

pmcalibration documentation built on Sept. 8, 2023, 5:10 p.m.