calibrate: Calibrate predicted probabilities using GAM

View source: R/calibrate.R

calibrateR Documentation

Calibrate predicted probabilities using GAM

Description

Calibrate predicted probabilities using a generalized additive model (GAM).

Usage

calibrate(
  true.labels,
  predicted.prob,
  pos.class = NULL,
  mod = c("gam", "glm"),
  k = 5,
  verbose = TRUE
)

Arguments

true.labels

Factor with true class labels

predicted.prob

Numeric vector with predicted probabilities

pos.class

Integer: Index of the positive class

mod

Character: Model to use for calibration. Either "gam" or "glm"

k

Integer: GAM degrees of freedom

verbose

Logical: If TRUE, print messages to the console

Value

mod: fitted GAM model. Use mod$fitted.values to get calibrated input probabilities; use predict(mod, newdata = newdata, type = "response") to calibrate other estimated probabilities.

Author(s)

EDG

Examples

## Not run: 
data(segment_logistic, package = "probably")

# Plot the calibration curve of the original predictions
dplot3_calibration(
  true.labels = segment_logistic$Class,
  predicted.prob = segment_logistic$.pred_poor,
  n_windows = 10,
  pos.class = 2
)

# Plot the calibration curve of the calibrated predictions
dplot3_calibration(
  true.labels = segment_logistic$Class,
  predicted.prob = calibrate(
    segment_logistic$Class,
    segment_logistic$.pred_poor
  )$fitted.values,
  n_windows = 10,
  pos.class = 2
)

## End(Not run)

egenn/rtemis documentation built on Nov. 22, 2024, 4:12 a.m.