Skip to contents

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

Usage

set_var_sexgender(mod, name)

Arguments

mod

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

name

The name of the sex or gender variable.

Value

A "bage_mod" object

Details

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

~ gender + region + gender:region

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

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

See also

Examples

## rename 'sex' variable to something unexpected
injuries2 <- nzl_injuries
injuries2$biological_sex <- injuries2$sex

## mod_pois does not recognize sex variable
mod <- mod_pois(injuries ~ age * biological_sex + year,
                data = injuries2,
                exposure = popn)
mod
#> 
#>     ------ Unfitted Poisson model ------
#> 
#> 
#>    injuries ~ age * biological_sex + year
#> 
#>   exposure = popn
#> 
#> 
#>                term  prior along n_par n_par_free
#>         (Intercept) NFix()     -     1          1
#>                 age   RW()   age    12         11
#>      biological_sex NFix()     -     2          2
#>                year   RW()  year    19         18
#>  age:biological_sex   RW()   age    24         22
#> 
#> 
#>  n_draw pr_mean_disp var_time var_age
#>    1000            1     year     age
#> 

## so we set the sex variable explicitly
mod |>
  set_var_sexgender(name = "biological_sex")
#> 
#>     ------ Unfitted Poisson model ------
#> 
#> 
#>    injuries ~ age * biological_sex + year
#> 
#>   exposure = popn
#> 
#> 
#>                term  prior along n_par n_par_free
#>         (Intercept) NFix()     -     1          1
#>                 age   RW()   age    12         11
#>      biological_sex NFix()     -     2          2
#>                year   RW()  year    19         18
#>  age:biological_sex   RW()   age    24         22
#> 
#> 
#>  n_draw pr_mean_disp var_time var_age  var_sexgender
#>    1000            1     year     age biological_sex
#>