## ----example 1----------------------------------------------------------------
library(EpiStandard)
library(dplyr)

standard_adult <- mergeAgeGroups(standardPopulation("Europe"),
                                 newGroups = c("20 to 29",
                                              "30 to 39",
                                              "40 to 49",
                                              "50 to 59",
                                              "60 to 69",
                                              "70 to 79",
                                              "80 to 89",
                                              "90 to 150"),
                                 ageRange = c(20,150))

standard_adult |> glimpse()

standard_child <- mergeAgeGroups(standardPopulation("Europe"),
                                 newGroups = c("0 to 9",
                                               "10 to 19"),
                                 ageRange = c(0,19))

standard_child |> glimpse()

## ----example 2----------------------------------------------------------------
df_study <- data.frame(country=rep(c('UK',"France"), c(4,4)),
                       age_group=rep(c('15-24','25-44','45-64','65-150'),2),
                       deaths=c(87,413,2316,3425,279,3254,9001,8182),
                       fu=c(80259,133440,142670,92168,20036,32693,14947,2077))

## ----example 3----------------------------------------------------------------
standard <- mergeAgeGroups(standardPopulation("Europe"),
                           newGroups =c('0-14','15-24','25-44','45-64','65-150'))

standard |> glimpse()

## ----example 4----------------------------------------------------------------

res <- directlyStandardiseRates(
  data = df_study,
  event = "deaths",
  denominator = "fu",
  strata = c("country"),
  refdata = standard,
  addMissingGroups = TRUE
)

res |> glimpse()

## ----example 5----------------------------------------------------------------
res <- directlyStandardiseRates(
  data = df_study,
  event = "deaths",
  denominator = "fu",
  strata = "country",
  refdata = standard,
  addMissingGroups = FALSE
)

res |> glimpse()

