Description Usage Arguments Details Value Examples
View source: R/process_dataset.R
For each series in dataset
, forecasts
are generated for all methods in methods
.
1 | calc_forecasts(dataset, methods, n.cores = 1)
|
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. |
dataset
must be a list with each element having the following format:
A time series object ts
with the historical data.
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.
A list with the elements having the following structure
A time series object ts
with the historical data.
The number of required forecasts.
A matrix with F rows and h
columns. Each row contains
the forecasts of each method in methods
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.