Skip to contents

The R package conformalForecast provides methods and tools for performing multistep-ahead time series forecasting using conformal prediction methods including classical conformal prediction, adaptive conformal prediction, conformal PID control, and autocorrelated multistep-ahead conformal prediction.

Installation

You can install the development version of conformalForecast from GitHub with:

# install.packages("remotes")
remotes::install_github("xqnwang/conformalForecast")

You can also get the official release version from CRAN:

install.packages("conformalForecast")

Example

For a detailed tutorial and examples, please see the vignette.

This basic example shows how to perform classical conformal prediction and update the results when new observations become available:

library(conformalForecast)
library(forecast)

# Simulate time series from an AR(2) model
series <- arima.sim(n = 1000, list(ar = c(0.8, -0.5)), sd = sqrt(1))

# Time series cross-validation
far2 <- function(x, h, level) {
  Arima(x, order = c(2, 0, 0)) |>
    forecast(h = h, level)
}
fc <- cvforecast(series, forecastfun = far2, h = 3, level = c(80, 95),
                 forward = TRUE, initial = 1, window = 100)

# Classical conformal prediction
scpfc <- conformal(fc, method = "scp", symmetric = FALSE, ncal = 100,
                   rolling = TRUE)

# Update conformal prediction with newly available observations
scpfc_updated <- update(scpfc, new_data = c(1.5, 0.8, 2.3),
                        forecastfun = far2)

# Interval forecast accuracy
accuracy(scpfc_updated, byhorizon = TRUE)

# Mean coverage
coverage(scpfc_updated, window = 500, level = 95)

# Mean and median interval width
width(scpfc_updated, window = 500, level = 95, includemedian = TRUE)

License

This package is free and open source software, licensed under GPL-3.