Skip to contents

Specify which variable (if any) represents time. Functions mod_pois(), mod_binom(), and mod_norm() try to infer the time variable from variable names, but do not always get it right.

Usage

set_var_time(mod, name)

Arguments

mod

An object of class "bage_mod", created with mod_pois(), mod_binom(), or mod_norm().

name

The name of the time variable.

Value

A bage_mod object

Details

In an R formula, a 'variable' is different from a 'term'. For instance,

~ time + region + time:region

contains variables time and region, and terms time, region, and time:region.

By default, bage gives a term involving time a (RW()) prior. Changing the time variable via set_var_time() can change priors: see below for an example.

If set_var_time() is applied to a fitted model, it 'unfits' the model, deleting existing estimates.

See also

Examples

## rename time variable to something unusual
injuries2 <- nzl_injuries
injuries2$calendar_year <- injuries2$year

## mod_pois does not recognize time variable
mod <- mod_pois(injuries ~ age * ethnicity + calendar_year,
                data = injuries2,
                exposure = popn)
mod
#> 
#>     ------ Unfitted Poisson model ------
#> 
#> 
#>    injuries ~ age * ethnicity + calendar_year
#> 
#>   exposure = popn
#> 
#> 
#>           term  prior along n_par n_par_free
#>    (Intercept) NFix()     -     1          1
#>            age   RW()   age    12         11
#>      ethnicity NFix()     -     2          2
#>  calendar_year    N()     -    19         19
#>  age:ethnicity   RW()   age    24         22
#> 
#> 
#>  n_draw pr_mean_disp var_age
#>    1000            1     age
#> 

## so we set the time variable explicitly
## (which, as a side effect, changes the prior on
## the time main effect)
mod |>
  set_var_time(name = "calendar_year")
#> 
#>     ------ Unfitted Poisson model ------
#> 
#> 
#>    injuries ~ age * ethnicity + calendar_year
#> 
#>   exposure = popn
#> 
#> 
#>           term  prior         along n_par n_par_free
#>    (Intercept) NFix()             -     1          1
#>            age   RW()           age    12         11
#>      ethnicity NFix()             -     2          2
#>  calendar_year   RW() calendar_year    19         18
#>  age:ethnicity   RW()           age    24         22
#> 
#> 
#>  n_draw pr_mean_disp      var_time var_age
#>    1000            1 calendar_year     age
#>