tests/testthat/test-backdr_dr_bad.R

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

  data(whatif2dat)
  # out <- backdr_dr_bad(whatif2dat, formula = vl4 ~ A + lvlcont0, R = 500)
  out <- backdr_dr_bad(whatif2dat, formula = vl4 ~ A + lvlcont0,
                       exposure.name = "A", confound.names = "lvlcont0")
  out <- within(out, {
    estimate[term == "logRR"] <- exp(estimate[term == "logRR"])
    term[term == "logRR"] <- "RR"
  })
  out <- out[out$term %in% ids, ]
  # cat("\n", "out", "\n")
  # print(out)
  # cat("\n")

  data(fci_tbl_06_09)
  target <- fci_tbl_06_09
  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)
})
FrankLef/fciR documentation built on Nov. 12, 2023, 6:09 a.m.