Skip to contents

Use a random walk to model a main effect, or use multiple random walks to model an interaction. Typically used with age or time effects or with interactions that involve age or time.

Usage

RW(s = 1, along = NULL, zero_sum = FALSE)

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.

zero_sum

If TRUE, values must sum to 0 within each combination of the 'by' variables. Default is FALSE.

Value

An object of class "bage_prior_rw".

Details

If RW() is used with an interaction, separate random walks are constructed along the 'along' variable, within each combination of the 'by' variables.

Argument s controls the size of innovations. Smaller values for s tend to give smoother series.

Mathematical details

When RW() is used with a main effect,

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

and when it is used with an interaction,

$$\beta_{u,v} = \beta_{u,v-1} + \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

  • RW2() Second-order 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

RW()
#>   RW() 
#>          s: 1
#>      along: NULL
#>   zero_sum: FALSE
RW(s = 0.5)
#>   RW(s=0.5) 
#>          s: 0.5
#>      along: NULL
#>   zero_sum: FALSE
RW(along = "cohort")
#>   RW(along="cohort") 
#>          s: 1
#>      along: cohort
#>   zero_sum: FALSE