calc_forecasts: Generate Forecasts for a Time Series Dataset

Description Usage Arguments Details Value Examples

View source: R/process_dataset.R

Description

For each series in dataset, forecasts are generated for all methods in methods.

Usage

1
calc_forecasts(dataset, methods, n.cores = 1)

Arguments

dataset

The list containing the series. See details for the required format.

methods

A list of strings with the names of the functions that generate the forecasts.

n.cores

The number of cores to be used. n.cores > 1 means parallel processing.

Details

dataset must be a list with each element having the following format:

x

A time series object ts with the historical data.

h

The number of required forecasts.

methods is a list of strings with the names of the functions that generate the forecasts. The functions must exist and take as parameters (x, h), with x being the ts object with the input series and h the number of required forecasts (after the last observation of x). The output of these functions must be a vector or ts object of length h with the produced forecast. No additional parameters are required in the functions.

Value

A list with the elements having the following structure

x

A time series object ts with the historical data.

h

The number of required forecasts.

ff

A matrix with F rows and h columns. Each row contains the forecasts of each method in methods

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
auto_arima_forec <- function(x, h) {
  model <- forecast::auto.arima(x, stepwise=FALSE, approximation=FALSE)
  forecast::forecast(model, h=h)$mean
}

snaive_forec <- function(x,h) {
  model <- forecast::snaive(x, h=length(x))
  forecast::forecast(model, h=h)$mean
}
rw_drift_forec <- function(x, h) {
  model <- forecast::rwf(x, drift=TRUE, h=length(x))
 forecast::forecast(model, h=h)$mean
}

create_example_list <- function() {
  methods <- list("auto_arima_forec")
  methods <- append(methods, "snaive_forec")
  methods <- append(methods, "rw_drift_forec")
  methods
}
methods <- create_example_list()
forec_results <- calc_forecasts(Mcomp::M3[1:4], methods, n.cores=1)

robjhyndman/M4metalearning documentation built on May 21, 2019, 12:22 p.m.