set_var_age: Specify Age Variable

View source: R/bage_mod-functions.R

set_var_ageR Documentation

Specify Age Variable

Description

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

Usage

set_var_age(mod, name)

Arguments

mod

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

name

The name of the age variable.

Details

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

~ age + region + age:region

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

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

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

Value

A bage_mod object

See Also

  • set_var_sexgender() Set sex or gender variable

  • set_var_time() Set time variable

  • is_fitted() Test whether a model is fitted

  • internally, bage uses poputils::find_var_age() to locate age variables

Examples

## rename 'age' variable to something unusual
injuries2 <- nzl_injuries
injuries2$age_last_birthday <- injuries2$age

## mod_pois does not recognize age variable
mod <- mod_pois(injuries ~ age_last_birthday * ethnicity + year,
                data = injuries2,
                exposure = popn)
mod

## so we set the age variable explicitly
## (which, as a side effect, changes the prior on
## the age main effect)
mod |>
  set_var_age(name = "age_last_birthday")

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