tests/testthat/test-backdr_out.R

test_that("backdr_out", {
  ids <- c("EY0", "EY1", "RD")

  data(whatif2dat)
  out <- backdr_out(whatif2dat, formula = vl4 ~ A + lvlcont0,
                    exposure.name ="A", confound.names = "lvlcont0")
  out <- out[out$term %in% ids, ]
  # cat("\n", "out", "\n")
  # print(out)
  # cat("\n")

  data(fci_tbl_06_07)
  target <- fci_tbl_06_07
  target <- target[target$term %in% ids, ]
  # cat("\n", "target", "\n")
  # print(target)
  # cat("\n")

  check <- sum(abs(out$estimate - target$.estimate))
  expect_lt(check, 0.01)
})


test_that("backdr_out: Bootstrapping estimate", {
  data(whatif2dat)
  out <- boot_est(data = whatif2dat, func = backdr_out,
                  times = 100, alpha = 0.05, seed = NULL, transf = "exp",
                  terms = c("EY0", "EY1", "RD", "RR", "RR*", "OR"),
                  formula = vl4 ~ A + lvlcont0, exposure.name ="A",
                  confound.names = "lvlcont0")
  # cat("\n", "out", "\n")
  # print(out)
  # cat("\n")

  data(fci_tbl_06_07)
  target <- fci_tbl_06_07
  # cat("\n", "target", "\n")
  # print(target)
  # cat("\n")

  ids <- match(target$.estimate, out$.estimate, nomatch = 0L)
  check <- sum(abs(out$.estimate[ids] - target$.estimate))
  expect_lt(check, 0.01)
})
FrankLef/fciR documentation built on Nov. 12, 2023, 6:09 a.m.