Use a random walk with seasonal effects to model a main effect, or use multiple random walks, each with their own seasonal effects, to model an interaction. Typically used with main effects or interactions that involve time.
Arguments
- n_seas
Number of seasons
- s
Scale for prior for innovations in the random walk. Default is
1
.- s_seas
Scale for innovations in seasonal effects. Default is
0
.- sd_seas
Standard deviation for initial values of seasonal effects. Default is
1
.- along
Name of the variable to be used as the 'along' variable. Only used with interactions.
- zero_sum
If
TRUE
, values must sum to 0 within each combination of the 'by' variables. Default isFALSE
.
Details
If RW_Seas()
is used with an interaction,
separate series are used for
the 'along' variable within
each combination of the
'by' variables.
Argument s
controls the size of innovations in the random walk.
Smaller values for s
tend to give smoother series.
Argument n_seas
controls the number of seasons
.
When using quarterly data, for instance,
n_seas
should be 4
, and when using
monthly data, n_seas
should be 12
.
By default, the magnitude of seasonal effects
is fixed. However, setting s_seas
to a value
greater than zero produces seasonal effects
that evolve over time.
Mathematical details
When RW_Seas()
is used with a main effect,
$$\beta_j = \alpha_j + \lambda_j$$ $$\alpha_j \sim \text{N}(\alpha_{j-1}, \tau^2)$$ $$\lambda_j \sim \text{N}(\lambda_{j-n}, \omega^2),$$
and when it is used with an interaction,
$$\beta_{u,v} = \alpha_{u,v} + \lambda_{u,v}$$ $$\alpha_{u,v} \sim \text{N}(\alpha_{u,v-1}, \tau^2),$$ $$\lambda_{u,v} \sim \text{N}(\lambda_{u,v-n}, \omega^2)$$
where
\(\pmb{\beta}\) is the main effect or interaction;
\(\alpha_j\) or \(\alpha_{u,v}\) is an element of the random walk;
\(\lambda_j\) or \(\lambda_{u,v}\) is an element of the seasonal effect;
\(j\) denotes position within the main effect;
\(v\) denotes position within the 'along' variable of the interaction;
\(u\) denotes position within the 'by' variable(s) of the interaction; and
\(n\) is
n_seas
.
Parameter \(\omega\) has a half-normal prior
$$\omega \sim \text{N}^+(0, \text{s\_seas}^2),$$
where s_seas
is provided by the user. If
s_seas
is set to 0, then \(\omega\) is 0,
and the seasonal effects are fixed over time.
Parameter \(\tau\) has a half-normal prior
$$\tau \sim \text{N}^+(0, \text{s}^2),$$
where s
is provided by the user.
See also
RW()
Random walk without seasonal effectRW2_Seas()
Second-order random walk, with seasonal effectpriors Overview of priors implemented in bage
set_prior()
Specify prior for intercept, main effect, or interaction
Examples
RW_Seas(n_seas = 4) ## seasonal effects fixed
#> RW_Seas(n_seas=4)
#> n_seas: 4
#> s: 1
#> s_seas: 0
#> sd_seas: 1
#> along: NULL
#> zero_sum: FALSE
RW_Seas(n_seas = 4, s_seas = 0.5) ## seasonal effects evolve
#> RW_Seas(n_seas=4,s_seas=0.5)
#> n: NULL
#> s: 1
#> s_seas: 0.5
#> sd_seas: 1
#> along: NULL
#> zero_sum: FALSE