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.
Arguments
- mod
An object of class
"bage_mod", created withmod_pois(),mod_binom(), ormod_norm().- name
The name of the time variable.
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, set_var_time() unfits
the model, deleting existing estimates.
See also
set_var_age()Set age variableset_var_sexgender()Sex sex or gender variableis_fitted()Test if model has been fittedinternally, bage uses
poputils::find_var_time()to locate time variables
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 12
#> ethnicity NFix() - 2 2
#> calendar_year N() - 19 19
#> age:ethnicity RW() age 24 24
#>
#> disp: mean = 1
#>
#> n_draw var_age
#> 1000 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 12
#> ethnicity NFix() - 2 2
#> calendar_year RW() calendar_year 19 19
#> age:ethnicity RW() age 24 24
#>
#> disp: mean = 1
#>
#> n_draw var_time var_age
#> 1000 calendar_year age
#>