gears_optim: Optimization Method for the GEARS Method for Time Series...

Description Usage Arguments Details Value Author(s) Examples

View source: R/gears_optim.R

Description

This algorithm will search for the "best" size of the rolling sample and the "best" number of rolling samples. "Best" in the sense of minimizing the selected error measure.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
gears_optim(
  DATA,
  forecast.horizon,
  search.size.rs,
  search.number.rs,
  glm.family = c("gaussian", "binomial", "poisson", "Gamma", "quasi"),
  level = 95,
  details = FALSE,
  y.name = NULL,
  y.max.lags = NULL,
  x.names = NULL,
  x.max.lags = NULL,
  x.fixed.names = NULL,
  x.fixed.lags = NULL,
  x.interaction.names = NULL,
  x.interaction.lags = NULL,
  last.obs = NULL,
  use.intercept = c("both", "without", "with"),
  error.measure = c("mse", "mae", "mase", "smape", "owa"),
  betas.selection = c("last", "average", "both"),
  use.parallel = FALSE,
  num.cores = NULL,
  ...
)

Arguments

DATA

A data frame or a univariate time series.

forecast.horizon

Number of periods for forecasting.

search.size.rs

Vector with the number of observations in the rolling sample to be optimized.

search.number.rs

Vector with the number of rolling samples to be optimized.

glm.family

A description of the error distribution to be used in the model. See glm for details.

level

Confidence level for prediction intervals. Numeric value between 0 and 100.

details

If TRUE, the function outputs the entire glm object for all random samples for each forecast lead. To save memory, the default is FALSE.

y.name

The name of the Y (left-hand side) variable. If NULL (default), the function creates a temporary name.

y.max.lags

A numeric value that gives the maximum number of lags of the Y (left-hand side) variable (see Details). Can be NULL (default) if the past values of the Y variable are not included in the model.

x.names

List with names of the X (right-hand side) variables that have a maximum number of lags (see Details). Can be NULL (default) if univariate model or if your model does not have variables of this type.

x.max.lags

List of numeric values that give the maximum number of lags of the X (right-hand side) variables. Can be NULL (default).

x.fixed.names

List with names of the X (right-hand side) variables that have a fixed number of lags (see Details). Can be NULL (default) if univariate model or if your model does not have variables of this type.

x.fixed.lags

List of numeric values that give the fixed number of lags of the variables in x.fixed.names. Can be NULL (default).

x.interaction.names

List of character vectors with names of the variables to be included as interaction terms (see Details). Can be NULL (default) if your model does not have interaction terms.

x.interaction.lags

List of numeric vectors with lags of the variables to be included as interaction terms. List and numeric vectors should have the same length as the ones in x.interaction.names. Can be NULL (default) if your model does not have interaction terms.

last.obs

Index number of the last observation to be considered.

use.intercept

If use.intercept == "both" (default), the function returns all possible model equations with and without intercept. If use.intercept == "without", then the function returns all possible right-hand side equations without intercept. If use.intercept == "with", then only the right-hand side equations with intercept are returned.

error.measure

Error measure to be used when calculating the in-sample prediction errors.

betas.selection

If betas.selection == "last", the estimated coefficients from the last rolling sample will be used to obtain the out-of-sample forecasts. If betas.selection == "average", then the average of the coefficients from all rolling samples will be used. If betas.selection == "both", then two out-of-sample forecasts will be estimated (one with betas.selection == "last" and another with betas.selection == "average").

use.parallel

If parallel computing should be used. Default is FALSE.

num.cores

Number of cores to use if parallel computing is used. If use.parallel == TRUE, then the default is detectCores() - 1. For more details, see detectCores.

...

Further arguments passed to glm.

Details

If y.max.lags equals to a number, then all lags of y.name up to this number (and starting at 0) will be included in the list of variables to enter the right-hand side of the model equations. For example, if y.max.lags = 2, then Yt, Yt-1, Yt-2 will be included in the list of variables to enter the right-hand side of the equation.

Value

A data frame with five columns: "size.rs", "number.rs", "intercept", "betas" and the last one named after the selected error measure. The last column returns the minimum value for the selected error measure, and the columns "size.rs" and "number.rs" return the sample sizes and the number of rolling samples used to get this minimum. The column "intercept" gives information on whether the intercept was used ("with"), or not ("without") on the best model. The "betas" column tells which betas.selection returns the best results.

Author(s)

Gustavo Varela-Alvarenga

Examples

 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Univariate Time Series Forecasting - Data of class 'ts'.
# Using betas.selection = "last"
gears_optim(
  DATA                = datasets::WWWusage,
  forecast.horizon    = 12,
  search.size.rs      = c(20, 30),
  search.number.rs    = c(10, 12),
  level               = 95,
  details             = FALSE,
  glm.family          = "quasi",
  y.name              = NULL,
  y.max.lags          = 2,
  x.names             = NULL,
  x.max.lags          = NULL,
  x.fixed.names       = NULL,
  x.fixed.lags        = NULL,
  x.interaction.names = NULL,
  x.interaction.lags  = NULL,
  last.obs            = length(datasets::WWWusage),
  use.intercept       = "both",
  error.measure       = "mse",
  betas.selection     = "last",
  use.parallel        = FALSE,
   num.cores          = NULL
)

# Univariate Time Series Forecasting - Data of class 'ts'.
# Using betas.selection = "both"
gears_optim(
  DATA                = datasets::WWWusage,
  forecast.horizon    = 12,
  search.size.rs      = c(20, 30),
  search.number.rs    = c(10, 12),
  level               = 95,
  details             = FALSE,
  glm.family          = "quasi",
  y.name              = NULL,
  y.max.lags          = 2,
  x.names             = NULL,
  x.max.lags          = NULL,
  x.fixed.names       = NULL,
  x.fixed.lags        = NULL,
  x.interaction.names = NULL,
  x.interaction.lags  = NULL,
  last.obs            = length(datasets::WWWusage),
  use.intercept       = "both",
  error.measure       = "mse",
  betas.selection     = "both",
  use.parallel        = FALSE,
  num.cores           = NULL
)

gears_optim(
  DATA                = datasets::WWWusage,
  forecast.horizon    = 12,
  search.size.rs      = c(20, 30),
  search.number.rs    = c(10, 12),
  level               = 95,
  details             = FALSE,
  glm.family          = "quasi",
  y.name              = NULL,
  y.max.lags          = 2,
  x.names             = NULL,
  x.max.lags          = NULL,
  x.fixed.names       = NULL,
  x.fixed.lags        = NULL,
  x.interaction.names = NULL,
  x.interaction.lags  = NULL,
  last.obs            = length(datasets::WWWusage),
  use.intercept       = "with",
  error.measure       = "mse",
  betas.selection     = "both",
  use.parallel        = FALSE,
  num.cores           = NULL
)

# With Parallel Computing
# Univariate Time Series Forecasting - Data of class 'ts'.
## If num.cores = NULL, the function uses
## num.cores = parallel::detectCores() - 1
gears_optim(
  DATA                = datasets::WWWusage,
  forecast.horizon    = 12,
  search.size.rs      = c(20, 30),
  search.number.rs    = c(10, 12),
  level               = 95,
  glm.family          = "quasi",
  y.max.lags          = 2,
  use.intercept       = "both",
  error.measure       = "mse",
  betas.selection     = "last",
  use.parallel        = TRUE,
  num.cores           = NULL
)

gu-stat/gears documentation built on Oct. 20, 2021, 2:53 a.m.