Skip to contents

Use an autoregressive process of order 1 to model a main effect, or use multiple AR1 processes to model an interaction. Typically used with time effects or with interactions that involve time.

Usage

AR1(min = 0.8, max = 0.98, s = 1, along = NULL, zero_sum = FALSE)

Arguments

min, max

Minimum and maximum values for autocorrelation coefficient. Defaults are 0.8 and 0.98.

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_ar".

Details

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

Arguments min and max can be used to specify the permissible range for autocorrelation.

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

Mathematical details

When AR1() is used with a main effect,

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

and when it is used with an interaction,

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

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

Internally, AR1() 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.

Coefficient \(\phi\) is constrained to lie between min and max. Its prior distribution is

$$\phi = (\text{max} - \text{min}) \phi' - \text{min}$$

where

$$\phi' \sim \text{Beta}(2, 2).$$

References

  • AR1() is based on the TMB function AR1

  • The defaults for min and max are based on the defaults for forecast::ets().

See also

Examples

AR1()
#>   AR1() 
#>        min: 0.8
#>        max: 0.98
#>          s: 1
#>      along: NULL
#>   zero_sum: FALSE
AR1(min = 0, max = 1, s = 2.4)
#>   AR1(min=0,max=1,s=2.4) 
#>        min: 0
#>        max: 1
#>          s: 2.4
#>      along: NULL
#>   zero_sum: FALSE
AR1(along = "cohort")
#>   AR1(along="cohort") 
#>        min: 0.8
#>        max: 0.98
#>          s: 1
#>      along: cohort
#>   zero_sum: FALSE