Second-Order Random Walk Prior with First Order Autoregressive Errors
Source:R/bage_prior-constructors.R
RW2_AR1.RdUse one or more second-order random walks, combined with an AR1 error term, to model a main effect or an interaction. Typically used with time.
Usage
RW2_AR1(
s_rw = 1,
sd = 1,
sd_slope = 1,
s_ar = 1,
shape1 = 5,
shape2 = 5,
min = 0.8,
max = 0.98,
along = NULL,
con = c("none", "by")
)Arguments
- s_rw
Scale for the innovations in the RW2 process. Default is
1.- sd
Standard deviation for initial term in RW2 process. Default is
1. Can be0.- sd_slope
Standard deviation in the prior for the initial slope of RW2 process. Larger values imply steeper slopes. Default is 1.
- s_ar
Scale for the innovations in the AR1 process. Default is
1.- shape1, shape2
Parameters for beta-distribution prior for coefficients. Defaults are
5and5.- min, max
Minimum and maximum values for autocorrelation coefficient in AR1 process. Defaults are
0.8and0.98.- along
Name of the variable to be used as the 'along' variable. Only used with interactions.
- con
Constraints on parameters. Current choices are
"none"and"by". Default is"none". See below for details.
Details
If RW2_AR1() is used with an interaction,
separate random walks are constructed along
the 'along' variable, within each combination
of the 'by' variables.
Parameters controlling the RW2 process:
s_rwsdsd_slope
Parameters controlling the AR1 process:
s_arshape1shape2minmax
Mathematical details
When RW2_AR1() is used with a main effect,
$$\beta_j = \alpha_j + \epsilon_j$$ $$\alpha_1 \sim \text{N}(0, \mathtt{sd}^2)$$ $$\alpha_2 \sim \text{N}(\alpha_1, \mathtt{sd\_slope}^2)$$ $$\alpha_j \sim \text{N}(2\alpha_{j-1} - \alpha_{j-2}, \tau^2), \quad j = 3, \cdots, J$$ $$\epsilon_j = \phi \epsilon_{j-1} + \varepsilon_j$$ $$\varepsilon_j \sim \text{N}(0, \omega^2),$$
and when it is used with an interaction,
$$\beta_{u,v} = \alpha_{u,v} + \epsilon_{u,v}$$ $$\alpha_{u,1} \sim \text{N}(0, \mathtt{sd}^2)$$ $$\alpha_{u,2} \sim \text{N}(\alpha_{u,1}, \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$$ $$\epsilon_{u,v} = \phi \epsilon_{u,v-1} + \varepsilon_{u,v}$$ $$\varepsilon_{u,v} \sim \text{N}(0, \omega^2),$$
where
\(\pmb{\beta}\) is the main effect or interaction;
\(j\) denotes position within the main effect;
\(u\) denotes position within the 'by' variable(s) of the interaction; and
\(v\) denotes position within the 'along' variable of the interaction.
The \(\tau\) parameter in the random walk has prior $$\tau \sim \text{N}^+(0, \mathtt{s\_rw}^2)$$
Internally, RW2_AR() derives a value for \(\omega\) that
gives \(\epsilon_j\) or \(\epsilon_{u,v}\) a marginal
variance of \(\nu^2\). Parameter \(\nu\)
has a half-normal prior
$$\nu \sim \text{N}^+(0, \mathtt{s\_ar}^2).$$
Coefficient \(\phi\) is constrained
to lie between min and max.
Its prior distribution is
$$\phi = (\mathtt{max} - \mathtt{min}) \phi' - \mathtt{min}$$
where
$$\phi' \sim \text{Beta}(\mathtt{shape1}, \mathtt{shape2}).$$
Constraints
With some combinations of terms and priors, the values of
the intercept, main effects, and interactions
are only weakly identified.
This weak identifiability is
typically harmless. However, in some applications, such as
when trying to obtain interpretable values
for main effects and interactions, it can be helpful to increase
identifiability through the use of constraints, specified through the
con argument.
Current options for con 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.
See also
RW2_AR()Generalization ofRW2_AR1()Lin_AR1()Sepcial case ofRW2_AR1()RW2()Second-order random walkAR1()AR1 processpriors Overview of priors implemented in bage
set_prior()Specify prior for intercept, main effect, or interactionMathematical Details vignette
Examples
RW2_AR1()
#> RW2_AR1()
#> s_rw: 1
#> sd: 1
#> sd_slope: 1
#> s_ar: 1
#> shape1: 5
#> shape2: 5
#> min: 0.8
#> max: 0.98
#> along: NULL
#> con: none
RW2_AR1(sd_slope = 2, s_ar = 0.5)
#> RW2_AR1(sd_slope=2,s_ar=0.5)
#> s_rw: 1
#> sd: 1
#> sd_slope: 2
#> s_ar: 0.5
#> shape1: 5
#> shape2: 5
#> min: 0.8
#> max: 0.98
#> along: NULL
#> con: none