Use an autoregressive process to model a main effect, or use multiple autoregressive processes to model an interaction. Typically used with time effects or with interactions that involve time.
Details
If AR()
is used with an interaction,
separate AR processes are constructed along
the "along" variable, within each combination of the
"by" variables.
By default, the autoregressive processes
have order 2. Alternative choices can be
specified through the n_coef
argument.
Argument s
controls the size of innovations.
Smaller values for s
tend to give smoother estimates.
Mathematical details
When AR()
is used with a main effect,
$$\beta_j = \phi_1 \beta_{j-1} + \cdots + \phi_n \beta_{j-n} + \epsilon_j$$ $$\epsilon_j \sim \text{N}(0, \omega^2),$$
and when it is used with an interaction,
$$\beta_{u,v} = \phi_1 \beta_{u,v-1} + \cdots + \phi_n \beta_{u,v-n} + \epsilon_{u,v}$$ $$\epsilon_{u,v} \sim \text{N}(0, \omega^2),$$
where
\(\pmb{\beta}\) is the main effect or interaction;
\(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_coef
.
Internally, AR()
derives a value for \(\omega\) that
gives every element of \(\beta\) a marginal
variance of \(\tau^2\). Parameter \(\tau\)
has a half-normal prior
$$\tau \sim \text{N}^+(0, \text{s}^2),$$
where s
is provided by the user.
The autocorrelation coefficients \(\phi_1, \cdots, \phi_n\) are restricted to values between -1 and 1 that jointly lead to a stationary model. The quantity \(r = \sqrt{\phi_1^2 + \cdots + \phi_n^2}\) has the boundary-avoiding prior
$$r \sim \text{Beta}(2, 2).$$
References
AR()
is based on the TMB function ARk
See also
AR1()
Special case ofAR()
priors Overview of priors implemented in bage
set_prior()
Specify prior for intercept, main effect, or interaction
Examples
AR(n_coef = 3)
#> AR(n_coef=3)
#> n_coef: 3
#> min: -1
#> max: 1
#> s: 1
#> along: NULL
AR(n_coef = 3, s = 2.4)
#> AR(n_coef=3,s=2.4)
#> n_coef: 3
#> min: -1
#> max: 1
#> s: 2.4
#> along: NULL
AR(along = "cohort")
#> AR(along="cohort")
#> n_coef: 2
#> min: -1
#> max: 1
#> s: 1
#> along: cohort