library(binom)
x <- 10
n <- 20
binom.confint(x, n, methods = "prop.test", conf.level = 0.80)
# method x n mean lower upper
# 1 prop.test 10 20 0.5 0.299298 0.700702
binom.confint(x, n, methods = "prop.test", conf.level = 0.95)
# method x n mean lower upper
# 1 prop.test 10 20 0.5 0.299298 0.700702
It does work with binom.test though
binom.test(x, n, conf.level=0.80)$conf.int
# [1] 0.3381709 0.6618291
binom.test(x, n, conf.level=0.95)$conf.int
# [1] 0.2719578 0.7280422
This seems to be a bug in the package. According to the docs for the
methodsargument:However, if we look at the source:
You can see that the
conf.levelargument is not passed toprop.test(), so it always uses the default (0.95). It should say:This would lead to different output for different CIs:
I am not entirely sure how to fix this. The Github repo seems to be read-only so you can't open an issue or Pull Request. Perhaps you could contact the package maintainers using the details on the CRAN page. In the meantime you could try the hot fix below.
Hot fix
This is not the way to build a robust codebase but if you need a short-term solution you can patch the function like this:
Then we can run
binom.confin2: