| scp | R Documentation |
Compute prediction intervals and other information by applying the classical split conformal prediction (SCP) method.
scp(
object,
alpha = 1 - 0.01 * object$level,
symmetric = FALSE,
ncal = 10,
rolling = FALSE,
quantiletype = 1,
weightfun = NULL,
kess = FALSE,
update = FALSE,
na.rm = TRUE,
...
)
object |
An object of class |
alpha |
A numeric vector of significance levels to achieve a desired
coverage level |
symmetric |
If |
ncal |
Length of the calibration set. If |
rolling |
If |
quantiletype |
An integer between 1 and 9 determining the type of
quantile estimator to be used. Types 1 to 3 are for discontinuous
quantiles, types 4 to 9 are for continuous quantiles. See the
|
weightfun |
Function to return a vector of weights used for the sample
quantile computation. Its first argument must be an integer indicating
the number of observations for which weights are generated. Defaults to
|
kess |
If |
update |
If |
na.rm |
If |
... |
Other arguments are passed to |
Consider a vector s_{t+h|t} that contains the nonconformity scores for
the h-step-ahead forecasts.
If symmetric is TRUE, s_{t+h|t}=|e_{t+h|t}|. When
rolling is FALSE, the (1-\alpha)-quantiles
\hat{q}_{t+h|t} are computed successively on expanding calibration
sets s_{1+h|1},\dots,s_{t|t-h}, for t=\mathrm{ncal}+h,\dots,T.
Then the prediction intervals will be
[\hat{y}_{t+h|t}-\hat{q}_{t+h|t}, \hat{y}_{t+h|t}+\hat{q}_{t+h|t}].
When rolling is TRUE, the calibration sets will be of the same
length ncal.
If symmetric is FALSE, s_{t+h|t}^{u}=e_{t+h|t} for the
upper interval bounds and s_{t+h|t}^{l} = -e_{t+h|t} for the lower
bounds. Instead of computing the (1-\alpha)-quantile, the
(1-\alpha/2)-quantiles for the lower bound \hat{q}_{t+h|t}^{l}
and the upper bound \hat{q}_{t+h|t}^{u} are calculated based on their
nonconformity scores, respectively. Then the prediction intervals will be
[\hat{y}_{t+h|t}-\hat{q}_{t+h|t}^{l}, \hat{y}_{t+h|t}+\hat{q}_{t+h|t}^{u}].
A list of class
c("scp", "cpforecast", "cvforecast", "forecast") with the
following components:
x |
The original time series. |
series |
The name of the series |
xreg |
Exogenous predictor variables used, if applicable. |
method |
A character string "scp". |
cp_times |
An integer vector giving the number of conformal predictions performed in cross-validation for each forecast horizon. |
MEAN |
Point forecasts as a multivariate time series, where the
|
ERROR |
Forecast errors given by
|
LOWER |
A list containing lower bounds for prediction intervals for
each |
UPPER |
A list containing upper bounds for prediction intervals for
each |
level |
The confidence values associated with the prediction intervals. |
call |
The matched call. |
model |
A list containing information about the conformal prediction
model: the resolved arguments in |
If mean is included in the object, the components
mean, lower, and upper will also be returned, showing
the information about the test set forecasts generated using all
available observations.
cvforecast to produce object,
update.cpforecast to extend the results with new
observations, and weighted_quantile for the
weighted quantile estimator used here.
Other conformal prediction methods:
acmcp(),
acp(),
conformal(),
pid()
# Simulate time series from an AR(2) model
library(forecast)
set.seed(1)
series <- arima.sim(n = 200, 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 = 95, window = 50)
# Classical conformal prediction with equal weights
scpfc <- scp(fc, ncal = 50, rolling = TRUE)
print(scpfc)
summary(scpfc)
# Classical conformal prediction with exponential weights
expweight <- function(n) {
0.99^{n+1-(1:n)}
}
scpfc_exp <- scp(fc, ncal = 50, rolling = TRUE,
weightfun = expweight, kess = TRUE, quantiletype = 7)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.