Skip to contents

Assigns the same weight to each season within a period, but exponentially decays across periods. For example, for a period length of 12, the most recent 12 weights will be equal, and higher than the next 12 weights that follow. See examples for an illustration of this idea.

Usage

weights_seasonal_decay(alpha_seasonal_decay, n, period_length)

Arguments

alpha_seasonal_decay

A value between 0 and 1 that determines how quick the exponential decay in the weights is

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

Value

A numeric vector of n values between 0 and 1 that sum up to 1

Examples

round(
  weights_seasonal_decay(
    alpha_seasonal_decay = 0.5, n = 19L, period_length = 7L
  ),
  2
)
#>  [1] 0.02 0.02 0.02 0.02 0.02 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.09 0.09 0.09
#> [16] 0.09 0.09 0.09 0.09

weights_seasonal_decay(alpha_seasonal_decay = 1, n = 19L, period_length = 7L)
#>  [1] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
#>  [8] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.1428571 0.1428571
#> [15] 0.1428571 0.1428571 0.1428571 0.1428571 0.1428571
weights_seasonal_decay(alpha_seasonal_decay = 0, n = 19L, period_length = 7L)
#>  [1] 0.05263158 0.05263158 0.05263158 0.05263158 0.05263158 0.05263158
#>  [7] 0.05263158 0.05263158 0.05263158 0.05263158 0.05263158 0.05263158
#> [13] 0.05263158 0.05263158 0.05263158 0.05263158 0.05263158 0.05263158
#> [19] 0.05263158

# no full period
weights_seasonal_decay(alpha_seasonal_decay = 1, n = 4L, period_length = 7L)
#> [1] 0.25 0.25 0.25 0.25