tests/test-dialysis.R

## Reference values for the dialysis data at alpha = 0.05
library(posthocbounds)

se <- (log(dialysis$upper) - log(dialysis$lower)) / (2 * 1.959964)
z <- (log(1.2 * 22.2) - log(dialysis$mortality)) / se
fit <- combined_bound(z)

stopifnot(fit$m == 6641)
comp <- fit$components
stopifnot(comp[["cutoff"]] == 6640, comp[["max_p"]] == 6641,
          round(comp[["threshold_bernstein"]]) == 1617,
          round(comp[["threshold_chernoff"]]) == 1563,
          round(comp[["centered"]]) == 2105,
          fit$false_all == 1563)

td <- true_discoveries(fit, list(
  CA = dialysis$state == "CA", NY = dialysis$state == "NY",
  profit = dialysis$ownership == "for-profit",
  top100 = order(-z)[1:100], top1000 = order(-z)[1:1000], top3000 = order(-z)[1:3000]))
stopifnot(identical(td$true_at_least, c(62L, 33L, 4505L, 83L, 922L, 2592L)))

rb <- ranked_bounds(fit, c(1, 10, 100, 1000, 6641))
stopifnot(identical(rb$true_at_least[c(1, 3, 4, 5)], c(1L, 83L, 922L, 5078L)))

ht <- hypothesis_table(fit, sort = TRUE)
stopifnot(abs(ht$fdp_at_most[2] - 0.070716) < 1e-6,
          abs(ht$fdp_at_most[6641] - 0.235356) < 1e-6,
          sum(ht$significant) == 1)

## the same result from p-values
fit_p <- combined_bound(p = pnorm(z, lower.tail = FALSE))
stopifnot(isTRUE(all.equal(fit_p$components, fit$components)))

Try the posthocbounds package in your browser

Any scripts or data that you put into this service are public.

posthocbounds documentation built on Nov. 28, 2026, 1:08 a.m.