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, it '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 <- 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
#>
#> (Intercept) ~ NFix()
#> age ~ RW()
#> ethnicity ~ NFix()
#> calendar_year ~ N()
#> age:ethnicity ~ RW()
#>
#> term n_par n_par_free
#> age 12 12
#> ethnicity 2 2
#> calendar_year 19 19
#> age:ethnicity 24 24
#>
#> dispersion: mean=1
#> exposure: popn
#> var_age: age
#> n_draw: 1000
## 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
#>
#> (Intercept) ~ NFix()
#> age ~ RW()
#> ethnicity ~ NFix()
#> calendar_year ~ RW()
#> age:ethnicity ~ RW()
#>
#> term n_par n_par_free
#> age 12 12
#> ethnicity 2 2
#> calendar_year 19 19
#> age:ethnicity 24 24
#>
#> dispersion: mean=1
#> exposure: popn
#> var_age: age
#> var_time: calendar_year
#> n_draw: 1000