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.
Arguments
- mod
An object of class
"bage_mod"
, created withmod_pois()
,mod_binom()
, ormod_norm()
.- name
The name of the sex or gender variable.
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
set_var_age()
Set age variableset_var_time()
Set time variableis_fitted()
Test whether model is fittedinternally, bage uses
poputils::find_var_sexgender()
to locate sex or gender variablesinternally, bage uses
poputils::find_label_female()
to locate female categories within a sex or gender variableinternally, bage uses
poputils::find_label_male()
to locate male categories within a sex or gender variable
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
#>