View source: R/bage_prior-constructors.R
RW2_Seas | R Documentation |
Use a second-oder random walk with seasonal effects as a model for a main effect, or use multiple second-order random walks, each with their own seasonal effects, as a model for an interaction. Typically used with temrs that involve time.
RW2_Seas(
n_seas,
s = 1,
sd = 1,
sd_slope = 1,
s_seas = 0,
sd_seas = 1,
along = NULL,
con = c("none", "by")
)
n_seas |
Number of seasons |
s |
Scale for prior for innovations in
random walk. Default is |
sd |
Standard deviation
of initial value. Default is |
sd_slope |
Standard deviation
for initial slope of random walk. Default is |
s_seas |
Scale for innovations
in seasonal effects. Default is |
sd_seas |
Standard deviation for
initial values of seasonal effects.
Default is |
along |
Name of the variable to be used as the 'along' variable. Only used with interactions. |
con |
Constraints on parameters.
Current choices are |
If RW2_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 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.
Object of class
"bage_prior_rw2randomseasvary"
,
"bage_prior_rw2randomseasfix"
,
"bage_prior_rw2zeroseasvary"
, or
"bage_prior_rw2zeroseasfix"
.
When RW2_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_2 \sim \text{N}(0, \mathtt{sd\_slope}^2)
\alpha_j \sim \text{N}(2 \alpha_{j-1} - \alpha_{j-2}, \tau^2), \quad j = 3, \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,2} \sim \text{N}(0, \mathtt{sd\_slope}^2)
\alpha_{u,v} \sim \text{N}(2 \alpha_{u,v-1} - \alpha_{u,v-2}, \tau^2), \quad v = 3, \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 the seasonal effects are fixed over time.
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.
RW2()
Second-order random walk without seasonal effect
RW_Seas()
Random walk with seasonal effect
priors Overview of priors implemented in bage
set_prior()
Specify prior for intercept,
main effect, or interaction
RW2_Seas(n_seas = 4) ## seasonal effects fixed
RW2_Seas(n_seas = 4, s_seas = 0.5) ## seasonal effects evolve
RW2_Seas(n_seas = 4, sd = 0) ## first term in random walk fixed at 0
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.