View source: R/initialize_states.R
initialize_states | R Documentation |
Perform a robust initialization of seasonal, local-linear trend, and level components given a suspected period length and the time series.
initialize_states(
y,
m,
method,
s = NULL,
seasonality_threshold = 0.5,
init_window_length = 5
)
y |
Input time series to fit the model against |
m |
Scalar indicating the period length of the potential seasonality |
method |
Are we using an |
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 |
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. |
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"
.
tulip()
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.