Skip to contents

Use a second-oder random walk to model a main effect, or use multiple second-order random walks 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.

Usage

RW2(s = 1, along = NULL)

Arguments

s

Scale for the prior for the innovations. Default is 1.

along

Name of the variable to be used as the "along" variable. Only used with interactions.

Value

An object of class "bage_prior_rw2".

Details

If RW2() 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 RW() is used with a main effect,

$$\beta_j = 2 \beta_{j-1} - \beta_{j-2} + \epsilon_j$$ $$\epsilon_j \sim \text{N}(0, \tau^2),$$

and when it is used with an interaction,

$$\beta_{u,v} = 2\beta_{u,v-1} - \beta_{u,v-2} + \epsilon_{u,v}$$ $$\epsilon_{u,v} \sim \text{N}(0, \tau^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; and

  • \(u\) denotes position within the "by" variable(s) of the interaction.

Parameter \(\tau\) has a half-normal prior $$\tau \sim \text{N}^+(0, \text{s}^2),$$ where s is provided by the user.

See also

  • RW() Random walk

  • AR() Autoregressive with order k

  • AR1() Autoregressive with order 1

  • Sp() Smoothing via splines

  • SVD() Smoothing of age via singular value decomposition

  • priors Overview of priors implemented in bage

  • set_prior() Specify prior for intercept, main effect, or interaction

Examples

RW2()
#>   RW2() 
#>        s: 1
#>    along: NULL
RW2(s = 0.5)
#>   RW2(s=0.5) 
#>        s: 0.5
#>    along: NULL