View source: R/bage_mod-functions.R
| set_var_time | R Documentation |
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.
set_var_time(mod, name)
mod |
An object of class |
name |
The name of the time variable. |
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.
A bage_mod object
set_var_age() Set age variable
set_var_sexgender() Sex sex or gender variable
is_fitted() Test if model has been fitted
internally, bage uses poputils::find_var_time()
to locate time variables
## 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
## 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.