diff --git a/R/adjust-numeric-calibration.R b/R/adjust-numeric-calibration.R index 65c2ba4..ab78a16 100644 --- a/R/adjust-numeric-calibration.R +++ b/R/adjust-numeric-calibration.R @@ -3,6 +3,29 @@ #' @param x A [container()]. #' @param calibrator A pre-trained calibration method from the \pkg{probably} #' package, such as [probably::cal_estimate_linear()]. +#' @examples +#' library(modeldata) +#' library(probably) +#' library(tibble) +#' +#' # create example data +#' set.seed(1) +#' dat <- tibble(y = rnorm(100), y_pred = y/2 + rnorm(100)) +#' +#' dat +#' +#' # calibrate numeric predictions +#' reg_cal <- cal_estimate_linear(dat, truth = y, estimate = y_pred) +#' +#' # specify calibration +#' reg_ctr <- +#' container(mode = "regression") %>% +#' adjust_numeric_calibration(reg_cal) +#' +#' # "train" container +#' reg_ctr_trained <- fit(reg_ctr, dat, outcome = y, estimate = y_pred) +#' +#' predict(reg_ctr, dat) #' @export adjust_numeric_calibration <- function(x, calibrator) { check_container(x) diff --git a/man/adjust_numeric_calibration.Rd b/man/adjust_numeric_calibration.Rd index 6c13706..f8e6315 100644 --- a/man/adjust_numeric_calibration.Rd +++ b/man/adjust_numeric_calibration.Rd @@ -15,3 +15,27 @@ package, such as \code{\link[probably:cal_estimate_linear]{probably::cal_estimat \description{ Re-calibrate numeric predictions } +\examples{ +library(modeldata) +library(probably) +library(tibble) + +# create example data +set.seed(1) +dat <- tibble(y = rnorm(100), y_pred = y/2 + rnorm(100)) + +dat + +# calibrate numeric predictions +reg_cal <- cal_estimate_linear(dat, truth = y, estimate = y_pred) + +# specify calibration +reg_ctr <- + container(mode = "regression") \%>\% + adjust_numeric_calibration(reg_cal) + +# "train" container +reg_ctr_trained <- fit(reg_ctr, dat, outcome = y, estimate = y_pred) + +predict(reg_ctr, dat) +}