[Experimental]

Produces forecast distributions using split conformal prediction rather than the model's own distributional assumptions. This can give better calibrated intervals when the model's errors are biased or poorly described by its assumed distribution.

The forecast distribution is obtained as follows:

  1. The model is refit on an expanding window of its history (starting with its first initial observations), forecasting up to h steps ahead from each origin to obtain out-of-sample errors.

  2. The errors for each forecast horizon are used as its calibration set. Forecasts for horizons with fewer than min_calibration errors can't be calibrated, and are NA (with a warning).

  3. The quantiles of the calibration errors are added to the model's point forecast to give the forecast distribution.

conformal_scp(model, n_quantiles = 5000, min_calibration = 20, initial = 10)

Arguments

model

A fitted model (e.g. mutate(ets = conformal_scp(ets))), or a model specification (e.g. model(ets = conformal_scp(ETS(y)))).

n_quantiles

The number of quantiles of the calibration errors used to represent each forecast distribution.

min_calibration

The minimum number of out-of-sample errors needed to calibrate a forecast horizon.

initial

The number of observations in the first (shortest) window the model is refit on. Forecasts from models fit to very few observations can be poor, which inflates the calibration errors (and so the intervals), while a larger initial leaves fewer errors to calibrate with. It must be less than the number of observations of each series.

Details

This differs from textbook split conformal prediction in a few ways:

  • The calibration errors come from rolling-origin refits of the model (time series cross-validation) rather than a single split of the data, so there's no finite-sample coverage guarantee.

  • The forecast distribution is a distributional::dist_sample() of n_quantiles quantiles of the calibration errors (on an evenly spaced grid of probabilities), added to the model's point forecast. Any interval can be computed from it with hilo(), and intervals needn't be symmetric. The quantiles are the conformal order statistics of the errors, with those beyond the observed errors truncated to the most extreme error.

  • The mean of the forecast distribution (.mean) is the model's point forecast plus the mean of these quantiles, so it is shifted from the model's own point forecast when its errors are biased.

Calibration refits the model for every origin of its history, which can be slow for long series or slow to estimate models. Refits of the first, shortest windows which fail are left out, and warnings from the refits aren't shown. Fitted models only keep their response, so models that use other data (such as exogenous regressors) can't be refit to calibrate them, and aren't supported yet.

conformal_scp() only changes forecasts. It uses the point forecasts of the model it wraps (without any simulation from simulate_iid() or bootstrap_iid()), and generate() simulates from that model as usual.

References

Wang, X., & Hyndman, R.J. (2024). conformalForecast: Conformal Prediction for Time Series Forecasting. https://github.com/xqnwang/conformalForecast

Examples

library(fable)
library(tsibbledata)
library(dplyr)
aus_production %>%
  slice_tail(n = 44) %>%
  model(snaive = SNAIVE(Beer)) %>%
  mutate(snaive = conformal_scp(snaive)) %>%
  forecast(h = 4)
#> # A fable: 4 x 4 [1Q]
#> # Key:     .model [1]
#>   .model Quarter         Beer .mean
#>   <chr>    <qtr>       <dist> <dbl>
#> 1 snaive 2010 Q3 sample[5000]  418.
#> 2 snaive 2010 Q4 sample[5000]  487.
#> 3 snaive 2011 Q1 sample[5000]  412.
#> 4 snaive 2011 Q2 sample[5000]  373.