Skip to contents

Assigns the largest weight to the same season of the period with length period_length, and exponentially decaying weights to the neighboring seasons. The most recent value in the resulting weights vector will be assigned the second-highest weight as it is the direct neighbor of the current season. See examples for illustrations of this.

Usage

weights_seasonal(alpha_seasonal, n, period_length)

Arguments

alpha_seasonal

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(alpha_seasonal = 0.25, n = 8, period_length = 7L),
  3
)
#> [1] 0.144 0.192 0.144 0.108 0.081 0.081 0.108 0.144

round(
  weights_seasonal(alpha_seasonal = 0.75, n = 27, period_length = 12L),
  3
)
#>  [1] 0.004 0.017 0.068 0.273 0.068 0.017 0.004 0.001 0.000 0.000 0.000 0.001
#> [13] 0.004 0.017 0.068 0.273 0.068 0.017 0.004 0.001 0.000 0.000 0.000 0.001
#> [25] 0.004 0.017 0.068

# "seasonal mean" weights
weights_seasonal(alpha_seasonal = 1, n = 30, period_length = 7L)
#>  [1] 0.00 0.00 0.25 0.00 0.00 0.00 0.00 0.00 0.00 0.25 0.00 0.00 0.00 0.00 0.00
#> [16] 0.00 0.25 0.00 0.00 0.00 0.00 0.00 0.00 0.25 0.00 0.00 0.00 0.00 0.00 0.00

# mean weights
weights_seasonal(alpha_seasonal = 0, n = 30, period_length = 7L)
#>  [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