testthat::context("SIR") testthat::test_that("SIR w/ coh=ref=popEpi::sire", { ## don't skip on CRAN sire2 <- copy(popEpi::sire) sire2[, agegroup := cut(dg_age, breaks = c(0:17*5, Inf))] levels(sire2$agegroup) <- 1:18 sire2[, ex_y := year(ex_date)] sire2[, dur := as.integer(ex_date-dg_date)/365.242199] ltre <- ltable(sire2[status != 0], c("ex_y", "agegroup"), expr = list(obs=.N, pyrs=sum(dur))) setDT(ltre) ltre[is.na(pyrs), pyrs := 0] sibr2 <- copy(popEpi::sibr) sibr2[, agegroup := cut(dg_age, breaks = c(0:17*5, Inf))] levels(sibr2$agegroup) <- 1:18 sibr2[, ex_y := year(ex_date)] sibr2[, dur := as.integer(ex_date-dg_date)/365.242199] ltbr <- ltable(sibr2[status != 0], c("ex_y", "agegroup"), expr = list(obs=.N, pyrs=sum(dur))) setDT(ltbr) ltbr[is.na(pyrs), pyrs := 0] sl <- sir(coh.data=ltre, coh.obs="obs", coh.pyrs="pyrs", ref.data=ltre, ref.obs="obs", ref.pyrs="pyrs", adjust= c("agegroup","ex_y")) plot(sl) ## SIR w/ coh=ref=popEpi::sire ## don't skip on CRAN testthat::expect_equal(sl$sir, 1) testthat::expect_equal(sl$pyrs, 13783.81, tolerance=0.01) testthat::expect_equal(sl$expected, 4595) testthat::expect_equal(sl$observed, 4595) sl <- sir(coh.data=ltre, coh.obs="obs", coh.pyrs="pyrs", ref.data=ltbr, ref.obs="obs", ref.pyrs="pyrs", adjust= c("agegroup","ex_y")) ## SIR w/ coh=ref=popEpi::sire" testthat::expect_equal(sl$sir, 1.39, tolerance=0.01) testthat::expect_equal(sl$pyrs, 13783.81, tolerance=0.01) testthat::expect_equal(sl$expected, 3305.04, tolerance=0.01) testthat::expect_equal(sl$observed, 4595) }) # SIR mstate, subset + lexpand aggre --------------------------------------- # same model c <- lexpand( popEpi::sire[dg_date