set_var_time: Specify Time Variable

View source: R/bage_mod-functions.R

set_var_timeR Documentation

Specify Time Variable

Description

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.

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.

Value

A bage_mod object

See Also

  • 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

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

## 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")

bage documentation built on April 3, 2025, 8:53 p.m.