Could you help me find the one-sided exact binomial test formula?
I use this statistical test in R-language, but I can't find the formula for it.
Eng Wikipedia (https://en.wikipedia.org/wiki/Binomial_test) and RLang help gives me only examples without needed math description.
Thank you!
You did not state or show a particular test of interest to you, or say what you have tried. I will try to clarify the specific example in Wikipedia, which you have tried to understand.
A die is rolled 235 times and shows face six 51 times. If the die is fair, then then number $X$ of sixes seen is $X \sim Binom(235, 1/6),$ so that $E(X) = np = 235(1/6) = 34.17.$ Our observed number 51 of sixes seems a lot larger than 34, so we wonder if the die is unfair, specifically showing sixes more often than it 'should'.
Accordingly, we wish to test $H_0; p = 1/6$ against the right-sided alternative $H_a: p > 1/6$. The P-value of the test is $P(X > 51) = 1 - P(X \le 50).$ Wikipedia says this is .027. In R, this probability can be computed in either of two ways, using the binomial CDF
pbinomor PDFdbinom, respectively:Either way, this amounts to $\sum_{i=51}^{235} {235 \choose i} p^i (1-p)^{235-i}.$ This is also the 'formula' used in
binom.testto obtain the P-value:The difference between just using the CDF or PDF and using
binom.testis that the latter prints a lot of additional information about the test and an associated 95% confidence interval. The help screen at? binom.testgives some explanation and a reference for how the CI is found. This style of CI is notoriously conservative (possibly giving a smaller lower bound than necessary) but it guarantees 95% coverage probability.The one-sided version of the 'Agresti-Coull' (sometimes called 'plus-4') style of CI, based on the normal approximation to the binomial (applicable here), also provides a lower bound. It can be found as: