initialize_states: Initialize state components given time series

View source: R/initialize_states.R

initialize_statesR Documentation

Initialize state components given time series

Description

Perform a robust initialization of seasonal, local-linear trend, and level components given a suspected period length and the time series.

Usage

initialize_states(
  y,
  m,
  method,
  s = NULL,
  seasonality_threshold = 0.5,
  init_window_length = 5
)

Arguments

y

Input time series to fit the model against

m

Scalar indicating the period length of the potential seasonality

method

Are we using an additive or a multiplicative seasonal component?

s

An optional numeric vector representing the initial seasonal state component. If provided, the the seasonal component is not derived automatically. Instead, the user-provided seasonal state is used, and the components l and b are derived given the user-provided s. The provided s must be of length m + length(y), where the first m values are the states ahead of the observed time period of the time series y.

seasonality_threshold

A value between 0 and 1; a seasonal component is not used when the seasonal component's reduction of variance in the residuals is less than the threshold

init_window_length

How many observations should be used to fit initial level and trend after the seasonal component was removed? Ideally, one uses few to let changes in state occur later via smoothing. But too few observations can lead to unrobust results.

Details

A crucial component when fitting exponential smoothing models is the initialization of the model's state components (level, trend, seasonality).

A poorly chosen initialization can prevent the model from adjusting neatly to the data. At the same time, finding a good initialization can be hard as one essentially has to already fit to the entire series to properly distinguish impacts from trend and seasonality. Initialization for time series is a chicken-and-egg problem. Standard methods can additionally be susceptible to anomalies.

While initialize_states() can be applied by a user of the tulip package directly to find initial states to provide to the tulip() function's init_states argument, it will also be called internally by tulip() if no init_states are provided.

Optionally, the seasonality component can be provided as s. The initialization problem then reduces to identifying the level and trend components given the seasonal component. This way, a seasonal component can be transferred from a previously fitted, related time series, which is especially comfortable when the seasonality component is chosen to be multiplicative, via method = "multiplicative".

References

Ruben Crevits and Christophe Croux (2017). Forecasting using Robust Exponential Smoothing with Damped Trend and Seasonal Components.

https://dx.doi.org/10.2139/ssrn.3068634

Rob J. Hyndman, Anne B. Koehler, Ralph D. Snyder, and Simone Grose (2002). A State Space Framework for Automatic Forecasting using Exponential Smoothing Methods.

https://doi.org/10.1016/S0169-2070(01)00110-8

Rafael de Rezende, Katharina Egert, Ignacio Marin, Guilherme Thompson (2021). A White-boxed ISSM Approach to Estimate Uncertainty Distributions of Walmart Sales.

https://arxiv.org/abs/2111.14721

See Also

tulip()

Examples

y <- as.numeric(AirPassengers[1:68])
init_state <- initialize_states(
  y = y, m = 12, method = "multiplicative", seasonality_threshold = 0.5
)

plot(-11:length(y), c(rep(NA, 12), y), pch = 19, cex = 0.5)
lines(-11:length(y),
      (init_state$l + init_state$b*(-11:length(y))) * init_state$s)

lines(1:length(y), init_state$fitted_global, col = "blue")
lines(1:length(init_state$fitted_local),
      init_state$fitted_local, col = "red")

y <- tulip::flowers$flowers
init_state <- initialize_states(y = y, m = 12, method = "multiplicative")

plot(-11:length(y), c(rep(NA, 12), y), pch = 19, cex = 0.5)
lines(-11:length(y),
      (init_state$l + init_state$b*(-11:length(y))) * init_state$s)
init_state <- initialize_states(y = y, m = 12, method = "additive")
lines(-11:length(y),
      init_state$l + init_state$b*(-11:length(y)) + init_state$s,
      col = "red")

init_state <- initialize_states(y = y, m = 12, method = "additive",
                                init_window_length = 24)

lines(-11:length(y),
      init_state$l + init_state$b*(-11:length(y)) + init_state$s,
      col = "blue")


timradtke/heuristika documentation built on April 24, 2023, 1:55 a.m.