Open skirsch opened 11 months ago
If you replace 1 with a 0, there is no error:
julia> print(FisherExactTest(75, 285, 0, 1140))
Fisher's exact test
-------------------
Population details:
parameter of interest: Odds ratio
value under h_0: 1.0
point estimate: Inf
95% confidence interval: (78.46, Inf)
Test summary:
outcome with 95% confidence: reject h_0
two-sided p-value: <1e-48
Details:
contingency table:
75 285
0 1140
julia>
Huh, this is a fun edge case. The issue here is coming from confint
. Mimicking what's happening inside confint
, we start with the following setup:
using HypothesisTests, Roots, Distributions
using HypothesisTests: find_brackets
test = FisherExactTest(75, 285, 1, 1140)
distribution((; a, b, c, d), ω) =
FisherNoncentralHypergeometric(a + b, c + d, a + c, ω)
objective(test, ω, tail) = pvalue(distribution(test, ω), test.a; tail) - 0.05
The default tail is :both
, which actually calls confint(...; tail=:left)
and confint(...; tail=:right)
to construct the limits. Those in turn find a bracketing interval for the zero of objective
(the odds ratio such that a p-value from the specified tail of Fisher's noncentral hypergeometric distribution is 0.05) and pass them to the root finding function. This then begins with
find_brackets(ω -> objective(test, ω, :left))
which produces an interval of (5.0e-324, 1.0). However, that... isn't a bracketing interval for the optimum: the objective function doesn't actually have any roots in that interval. Now, if you try again with test = FisherExactTest(75, 285, 0, 1140)
, you actually get the same interval. Then why does one work and the other does not? It's because we explicitly handle the case where the first cell in the 2x2 table is equal to either extremum of the distribution for an odds ratio of 1. But when the cell is 1 instead of 0, we're 1 away from an extremum, so we don't hit the special case.
I suspect this is a problem with find_brackets
.