# Invert a Wald test to get a confidence interval
cs <- invert_test(
test_fn = function(theta) wald_test(estimate = 2.5, se = 0.8, null_value = theta),
grid = seq(0, 5, by = 0.01)
)
cs
lower(cs)
upper(cs)
# Compare with the analytical confint (should agree up to grid resolution)
confint(wald_test(estimate = 2.5, se = 0.8))
# Invert ANY user-defined test — no special support needed
my_test <- function(theta) {
stat <- (5.0 - theta)^2 / 2
hypothesis_test(stat = stat,
p.value = pchisq(stat, df = 1, lower.tail = FALSE), dof = 1)
}
invert_test(my_test, grid = seq(0, 10, by = 0.01))
Run the code above in your browser using DataLab