## specify model
mod <- mod_pois(injuries ~ age * sex + year,
data = nzl_injuries,
exposure = popn) |>
set_disp(mean = 0) |>
set_datamod_exposure(cv = 0.025)
## fit the model
mod <- mod |>
fit()
mod
## examine results - note the new variable
## '.popn' with estimates of the true
## population
aug <- mod |>
augment()
## allow different cv's for each sex
cv_sex <- data.frame(sex = c("Female", "Male"),
cv = c(0.03, 0.02))
mod <- mod |>
set_datamod_exposure(cv = cv_sex)
mod
## our outcome variable is confidentialized,
## so we recognize that in the model too
mod <- mod |>
set_confidential_rr3()
mod
## now a model where everyone aged 0-49
## receives one value for cv, and
## everyone aged 50+ receives another
library(poputils) ## for 'age_upper()'
library(dplyr, warn.conflicts = FALSE)
nzl_injuries_age <- nzl_injuries |>
mutate(age_group = if_else(age_upper(age) < 50,
"0-49",
"50+"))
cv_age <- data.frame(age_group = c("0-49", "50+"),
cv = c(0.05, 0.01))
mod <- mod_pois(injuries ~ age * sex + year,
data = nzl_injuries_age,
exposure = popn) |>
set_disp(mean = 0) |>
set_datamod_exposure(cv = cv_age)
Run the code above in your browser using DataLab