This function allows you to specify the method used to perform conformal prediction.
Usage
conformal(object, ...)
# S3 method for class 'cvforecast'
conformal(object, method = c("scp", "acp", "pid", "mcp"), ...)
Arguments
- object
An object of class
"cvforecast"
. It must have an argumentx
for original univariate time series, an argumentMEAN
for point forecasts andERROR
for forecast errors on validation set. See the results of a call tocvforecast
.- ...
Additional arguments to be passed to the selected conformal method.
- method
A character string specifying the conformal method to be applied. Possible options include
"scp"
(scp),"acp"
(acp),"pid"
(pid), and"mcp"
(mcp).
Examples
# Simulate time series from an AR(2) model
library(forecast)
series <- arima.sim(n = 1000, list(ar = c(0.8, -0.5)), sd = sqrt(1))
# Cross-validation forecasting
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 with equal weights
scpfc <- conformal(fc, method = "scp", symmetric = FALSE, ncal = 100, rolling = TRUE)
summary(scpfc)
#> SCP
#>
#> Call:
#> scp(object = object, symmetric = FALSE, ncal = 100, rolling = TRUE)
#>
#> cp_times = 799 (the forward step included)
#>
#> Forecasts of the forward step:
#> Cross-validation
#>
#> Call:
#> scp(object = object, symmetric = FALSE, ncal = 100, rolling = TRUE)
#>
#> fit_times = (the forward step included)
#>
#> Forecasts of the forward step:
#> Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
#> 1001 -0.5165515 -2.015214 0.910992 -2.615997 1.526088
#> 1002 -0.1132015 -2.043974 1.533047 -3.245547 3.232007
#> 1003 0.2844349 -1.819366 1.857624 -2.714702 3.733580
#>
#> Cross-validation error measures:
#> ME MAE MSE RMSE MPE MAPE MASE RMSSE Winkler_95 MSIS_95
#> CV 0.004 0.959 1.452 1.088 33.284 206.539 0.9 0.809 5.813 5.463
# ACP with asymmetric nonconformity scores and rolling calibration sets
acpfc <- conformal(fc, method = "acp", symmetric = FALSE, gamma = 0.005, ncal = 100, rolling = TRUE)
summary(acpfc)
#> ACP
#>
#> Call:
#> acp(object = object, gamma = 0.005, symmetric = FALSE, ncal = 100,
#> rolling = TRUE)
#>
#> cp_times = 799 (the forward step included)
#>
#> Forecasts of the forward step:
#> Cross-validation
#>
#> Call:
#> acp(object = object, gamma = 0.005, symmetric = FALSE, ncal = 100,
#> rolling = TRUE)
#>
#> fit_times = (the forward step included)
#>
#> Forecasts of the forward step:
#> Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
#> 1001 -0.5165515 NA NA NA NA
#> 1002 -0.1132015 NA NA NA NA
#> 1003 0.2844349 NA NA NA NA
#>
#> Cross-validation error measures:
#> ME MAE MSE RMSE MPE MAPE MASE RMSSE Winkler_95 MSIS_95
#> CV 0.004 0.959 1.452 1.088 33.284 206.539 0.9 0.809 NaN NaN