Description Usage Arguments Details Value References Examples
Point forecasts and prediction intervals of all forecasting methods
in methods
are calculated for each time series in dataset
.
1 |
dataset |
a list containing the time series. See details for the required format. |
methods |
a list of strings with the names of the functions that calculate point forecasts and prediction intervals for time series. |
level |
the confidence levels for prediction intervals, such as 80, 90. |
parallel |
logical. If |
num.cores |
the specified amount of parallel processes to be used if parallel = TRUE. |
dataset
must be a list with each element having the following format:
a time series object ts
with the historical data.
the amount of future time steps to forecast.
methods
a list of strings with the names of the functions
that calculate point forecasts and prediction intervals for time series.
The functions must exist and take as parameters (x
, h
, level
), where
x
is the ts
object with the input series,
h
is the amount of future time steps to forecast
and level
denotes confidence levels for prediction intervals.
The output of these functions must be
a list with forecs
(point forecasts), fitted
(fitted values),
pil
(lower bounds of prediction intervals) and
piu
(upper bounds of prediction intervals)
A list with the elements having the following structure
a time series object ts
with the historical data.
the amount of future time steps to forecast.
a matrix with F
rows and n
columns. Each row contains
the fitted values of each method in methods
.
a matrix with F
rows and h
columns. Each row contains
the forecasts of each method in methods
.
a list with each element being the matrix of lower bounds for certain confidence level.
a list with each element being the matrix of upper bounds for certain confidence level.
Montero-Manso et al. (2018).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | auto_arima_fun <- function(x, h, level) {
model <- forecast::auto.arima(x, stepwise=FALSE, approximation=FALSE)
forecs <- forecast::forecast(model, h=h)$mean
fitted <- forecast::forecast(model, h=h)$fitted
pil <- forecast::forecast(model, h=h, level=level)$lower
piu <- forecast::forecast(model, h=h, level=level)$upper
list(forecs=forecs, fitted=fitted, pil=pil, piu=piu)
}
ets_fun <- function(x, h, level) {
# for ets method, residuals != x - fitted
model <- forecast::ets(x)
forecs <- forecast::forecast(model, h=h)$mean
fitted <- forecast::forecast(model, h=h)$fitted
pil <- forecast::forecast(model, h=h, level=level)$lower
piu <- forecast::forecast(model, h=h, level=level)$upper
list(forecs=forecs, fitted=fitted, pil=pil, piu=piu)
}
tbats_fun <- function(x, h, level) {
# for tbats method, residuals != mean - fitted
model <- forecast::tbats(x, use.parallel=FALSE)
forecs <- forecast::forecast(model, h=h)$mean
fitted <- forecast::forecast(model, h=h)$fitted
pil <- forecast::forecast(model, h=h, level=level)$lower
piu <- forecast::forecast(model, h=h, level=level)$upper
list(forecs=forecs, fitted=fitted, pil=pil, piu=piu)
}
create_example_list <- function() {
methods_list <- list("auto_arima_fun")
methods_list <- append(methods_list, "ets_fun")
methods_list <- append(methods_list, "tbats_fun")
methods_list
}
methods <- create_example_list()
forec_results <- ts_forec(Mcomp::M3[1:5], methods, level = c(80, 90))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.