Skip to contents

Prediction intervals with coverage of at least 1 - alpha (split, CQR) or 1 - 2 alpha (CV+, jackknife+) in finite samples under exchangeability alone, from held-out residuals. The conformal quantile is the ceiling((1 - alpha)(n + 1))-th smallest of n scores (infinite when that rank exceeds n), as MAPIE's.

Usage

conformal_split(
  y,
  pred,
  test_pred,
  alpha = 0.1,
  score = c("absolute", "pearson", "scaled"),
  family = "",
  scale = NULL,
  test_scale = NULL,
  weights = NULL,
  test_weights = NULL,
  theta = NaN,
  power = NaN
)

conformal_cqr(y, lo, hi, test_lo, test_hi, alpha = 0.1)

conformal_plus(y, oof_pred, folds, fold_pred, alpha = 0.1)

conformal_intervals(
  model,
  data,
  y,
  newdata,
  method = c("cv+", "jackknife+", "split", "cqr"),
  alpha = 0.1,
  splits = NULL,
  score = c("absolute", "pearson"),
  family = ""
)

Arguments

y

Responses on the calibration (or training) rows.

pred, test_pred

Predictions on the calibration and test rows.

alpha

The miscoverage level.

score

"absolute", "pearson" or "scaled".

family

A family name, for "pearson".

scale, test_scale

Spreads, for "scaled".

weights, test_weights

Weights, or NULL.

theta, power

For the negative binomial and Tweedie.

lo, hi, test_lo, test_hi

Lower and upper quantile predictions.

oof_pred

Each training row's prediction by its fold's model.

folds

Each training row's fold (1, 2, ...).

fold_pred

A list of each fold's model's test predictions.

model

A fitted model, a list of two, or a fitting function.

data, newdata

Calibration (or training) and test data frames.

method

"split", "cqr", "cv+" or "jackknife+".

splits

For "cv+": a list of list(train, test) (1-based), each row in one test set; k_fold() with five folds by default.

Value

A data frame with lo and hi, one row a test row.

Details

conformal_split() scores a model's predictions on a calibration set: |y - pred| ("absolute", intervals pred +/- q), the Pearson residual of a family ("pearson", mu +/- q sqrt(V(mu))) or a residual over a given spread ("scaled", pred +/- q s); with weights and test_weights the quantile is the weighted one with each test row's weight at infinity. conformal_cqr() is conformalised quantile regression on a lower and an upper quantile model's predictions. conformal_plus() is CV+ (the jackknife+ with one fold a row) from each fold's model's out-of-fold and test predictions. conformal_intervals() does it from a model: for "split" a fitted model scored on data and y; for "cqr" a list of a fitted lower and upper quantile model; for "cv+" and "jackknife+" a function of a data frame and its responses returning a fitted model, fitted on each split's training rows. Every fitted model is read with predict(model, newdata).

Examples

conformal_split(0:18, rep(9, 19), 100, alpha = 0.1)
#>   lo  hi
#> 1 91 109
d <- data.frame(x = (0:39) %% 7)
y <- 1 + 0.5 * d$x + ((0:39 * 31) %% 7) - 3
fit <- function(data, y) stats::lm(y ~ x, data = cbind(data, y = y))
conformal_intervals(fit, d, y, data.frame(x = 3), method = "jackknife+")
#>           lo       hi
#> 1 -0.8395659 5.798164