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

## 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
#> 
#>   exposure = popn
#> 
#> 
#>                         term  prior             along n_par n_par_free
#>                  (Intercept) NFix()                 -     1          1
#>            age_last_birthday   RW() age_last_birthday    12         11
#>                    ethnicity NFix()                 -     2          2
#>                         year   RW()              year    19         18
#>  age_last_birthday:ethnicity    N()                 -    24         24
#> 
#> 
#>  n_draw pr_mean_disp var_time           var_age
#>    1000            1     year age_last_birthday
#>