Assigns weights that decay in three different directions as determined by
the combination of weights_exponential()
, weights_seasonal()
, and
weights_seasonal_decay()
.
Arguments
- alpha
The smoothing factor passed to
weights_exponential()
that determines the overall monotonic exponential weight component- alpha_seasonal
The smoothing factor passed to
weights_seasonal()
that determines the exponential weighting within a seasonal period- alpha_seasonal_decay
The smoothing factor passed to
weights_seasonal_decay()
that determines the exponential weighting of the seasonal periods- n
The number of weights to create; this is usually equal to the number of observations in a time series
- period_length
The length of the seasonal period to be modeled
Examples
weights <- weights_threedx(
alpha = 0.01,
alpha_seasonal = 0.05,
alpha_seasonal_decay = 0.01,
n = 17,
period_length = 5
)
print(weights)
#> [1] 0.05115383 0.05439003 0.05841513 0.05605492 0.05379007 0.05433341
#> [7] 0.05777077 0.06204605 0.05953914 0.05713352 0.05771063 0.06136164
#> [13] 0.06590267 0.06323993 0.06068478 0.06129776 0.06517572
if (require("ggplot2")) {
ggplot2::ggplot(
data.frame(index = seq_along(weights), weight = weights),
ggplot2::aes(x = index, y = weight)
) +
ggplot2::geom_col()
}
# random walk forecast
weights_threedx(
alpha = 1,
alpha_seasonal = 0,
alpha_seasonal_decay = 1,
n = 30,
period_length = 12
)
#> [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
# mean forecast
weights_threedx(
alpha = 0,
alpha_seasonal = 0,
alpha_seasonal_decay = 0,
n = 30,
period_length = 12
)
#> [1] 0.03333333 0.03333333 0.03333333 0.03333333 0.03333333 0.03333333
#> [7] 0.03333333 0.03333333 0.03333333 0.03333333 0.03333333 0.03333333
#> [13] 0.03333333 0.03333333 0.03333333 0.03333333 0.03333333 0.03333333
#> [19] 0.03333333 0.03333333 0.03333333 0.03333333 0.03333333 0.03333333
#> [25] 0.03333333 0.03333333 0.03333333 0.03333333 0.03333333 0.03333333
# seasonal mean forecast
weights_threedx(
alpha = 0,
alpha_seasonal = 1,
alpha_seasonal_decay = 0,
n = 30,
period_length = 12
)
#> [1] 0.0 0.0 0.0 0.0 0.0 0.0 0.5 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.5
#> [20] 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
# seasonal naive forecast
weights_threedx(
alpha = 0,
alpha_seasonal = 1,
alpha_seasonal_decay = 1,
n = 30,
period_length = 12
)
#> [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
# last year's mean forecast
weights_threedx(
alpha = 0,
alpha_seasonal = 0,
alpha_seasonal_decay = 1,
n = 30,
period_length = 12
)
#> [1] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
#> [7] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
#> [13] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
#> [19] 0.08333333 0.08333333 0.08333333 0.08333333 0.08333333 0.08333333
#> [25] 0.08333333 0.08333333 0.08333333 0.08333333 0.08333333 0.08333333