Use a random walk with seasonal effects as a model for a main effect, or use multiple random walks, each with their own seasonal effects, as a model for an interaction. Typically used with terms that involve time.
RW_Seas(
n_seas,
s = 1,
sd = 1,
s_seas = 0,
sd_seas = 1,
along = NULL,
con = c("none", "by")
)
Object of class
"bage_prior_rwrandomseasvary"
,
"bage_prior_rwrandomseasfix"
,
"bage_prior_rwzeroseasvary"
, or
"bage_prior_rwzeroseasfix"
.
Number of seasons
Scale for prior for innovations in
random walk. Default is 1
.
Standard deviation
of initial value. Default is 1
.
Can be 0
.
Scale for innovations
in seasonal effects. Default is 0
.
Standard deviation for
initial values of seasonal effects.
Default is 1
.
Name of the variable to be used as the 'along' variable. Only used with interactions.
Constraints on parameters.
Current choices are "none"
and "by"
.
Default is "none"
. See below for details.
When RW_Seas()
is used with a main effect,
$$\beta_j = \alpha_j + \lambda_j, \quad j = 1, \cdots, J$$ $$\alpha_1 \sim \text{N}(0, \mathtt{sd}^2)$$ $$\alpha_j \sim \text{N}(\alpha_{j-1}, \tau^2), \quad j = 2, \cdots, J$$ $$\lambda_j \sim \text{N}(0, \mathtt{sd\_seas}^2), \quad j = 1, \cdots, \mathtt{n\_seas} - 1$$ $$\lambda_j = -\sum_{s=1}^{\mathtt{n\_seas} - 1} \lambda_{j - s}, \quad j = \mathtt{n\_seas}, 2 \mathtt{n\_seas}, \cdots$$ $$\lambda_j \sim \text{N}(\lambda_{j-\mathtt{n\_seas}}, \omega^2), \quad \text{otherwise},$$
and when it is used with an interaction,
$$\beta_{u,v} = \alpha_{u,v} + \lambda_{u,v}, \quad v = 1, \cdots, V$$ $$\alpha_{u,1} \sim \text{N}(0, \mathtt{sd}^2)$$ $$\alpha_{u,v} \sim \text{N}(\alpha_{u,v-1}, \tau^2), \quad v = 2, \cdots, V$$ $$\lambda_{u,v} \sim \text{N}(0, \mathtt{sd\_seas}^2), \quad v = 1, \cdots, \mathtt{n\_seas} - 1$$ $$\lambda_{u,v} = -\sum_{s=1}^{\mathtt{n\_seas} - 1} \lambda_{u,v - s}, \quad v = \mathtt{n\_seas}, 2 \mathtt{n\_seas}, \cdots$$ $$\lambda_{u,v} \sim \text{N}(\lambda_{u,v-\mathtt{n\_seas}}, \omega^2), \quad \text{otherwise},$$
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; and
\(u\) denotes position within the 'by' variable(s) of the interaction.
Parameter \(\omega\) has a half-normal prior
$$\omega \sim \text{N}^+(0, \mathtt{s\_seas}^2).$$
If s_seas
is set to 0, then \(\omega\) is 0,
and seasonal effects are time-invariant.
Parameter \(\tau\) has a half-normal prior $$\tau \sim \text{N}^+(0, \mathtt{s}^2).$$
With some combinations of terms and priors, the values of the intercept, main effects, and interactions are are only weakly identified. For instance, it may be possible to increase the value of the intercept and reduce the value of the remaining terms in the model with no effect on predicted rates and only a tiny effect on prior probabilities. This weak identifiability is typically harmless. However, in some applications, such as forecasting, or when trying to obtain interpretable values for main effects and interactions, it can be helpful to increase identifiability through the use of constraints.
Current options for constraints are:
"none"
No constraints. The default.
"by"
Only used in interaction terms that include 'along' and
'by' dimensions. Within each value of the 'along'
dimension, terms across each 'by' dimension are constrained
to sum to 0.
If RW_Seas()
is used with an interaction,
a separate series is constructed
within each combination of the
'by' variables.
Argument s
controls the size of innovations in the random walk.
Smaller values for s
tend to produce smoother series.
Argument sd
controls variance in
initial values of the random walk. sd
can be 0
.
Argument n_seas
controls the number of seasons.
When using quarterly data, for instance,
n_seas
should be 4
.
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.
RW()
Random walk without seasonal effect
RW2_Seas()
Second-order random walk with seasonal effect
priors Overview of priors implemented in bage
set_prior()
Specify prior for intercept,
main effect, or interaction
RW_Seas(n_seas = 4) ## seasonal effects fixed
RW_Seas(n_seas = 4, s_seas = 0.5) ## seasonal effects evolve
RW_Seas(n_seas = 4, sd = 0) ## first term in random walk fixed at 0
Run the code above in your browser using DataLab