Skip to contents

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.

Value

A bage_mod object

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.

See also

Examples

## rename 'age' variable to something unusual
injuries2 <- 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
#> -- Unfitted Poisson model --
#> 
#>                    injuries ~ age_last_birthday * ethnicity + year
#> 
#>                 (Intercept) ~ NFix()
#>           age_last_birthday ~ N()
#>                   ethnicity ~ NFix()
#>                        year ~ RW()
#> age_last_birthday:ethnicity ~ N()
#> 
#>                         term n_par n_par_free
#>            age_last_birthday    12         12
#>                    ethnicity     2          2
#>                         year    19         19
#>  age_last_birthday:ethnicity    24         24
#> 
#>      dispersion: mean=1
#>        exposure: popn
#>        var_time: year
#>          n_draw: 1000

## 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")
#> -- Unfitted Poisson model --
#> 
#>                    injuries ~ age_last_birthday * ethnicity + year
#> 
#>                 (Intercept) ~ NFix()
#>           age_last_birthday ~ RW()
#>                   ethnicity ~ NFix()
#>                        year ~ RW()
#> age_last_birthday:ethnicity ~ N()
#> 
#>                         term n_par n_par_free
#>            age_last_birthday    12         12
#>                    ethnicity     2          2
#>                         year    19         19
#>  age_last_birthday:ethnicity    24         24
#> 
#>      dispersion: mean=1
#>        exposure: popn
#>         var_age: age_last_birthday
#>        var_time: year
#>          n_draw: 1000