Use a second-oder random walk with seasonal effects to model a main effect, or use multiple second-order random walks, each with their own seasonal effects, to model an interaction. A second-order random walk is effectively a random walk with drift where the drift term varies. It is typically used with main effects or interactions that involve time, where there are sustained trends upward or downward.
Details
If RW2_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
can change over time. However, setting s_seas
to 0
produces seasonal effects that are fixed,
eg where "January" effect is the same every year,
the "Feburary" effect is the same every year, and so on.
Mathematical details
When RW2_Seas()
is used with a main effect,
$$\beta_j = \alpha_j + \lambda_j$$ $$\alpha_j \sim \text{N}(2 \alpha_{j-1} - \alpha_{j-2}, \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}(2 \alpha_{u,v-1} - \alpha_{u,v-2}, \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
RW2()
Second-order random walk, without seasonal effectRW_Seas()
Random walk, with seasonal effectpriors Overview of priors implemented in bage
set_prior()
Specify prior for intercept, main effect, or interaction