# [R] Two-tailed exact binomial test with binom.test and sum(dbinom(...))

Stefan Evert stefanML at collocations.de
Sun Dec 14 13:54:25 CET 2014

```If your null hypothesis is that the probability of a success is 0.6, i.e. H0: p=0.6, then those

> (a) Let's also assume we have an H1 that there are more than 6
> successes
>
> (b) Now let's assume we have an H1 that there are fewer than 6
> successes
>
> (1). My understanding would be that, if we have an H1 that says "the
> number of successes won't be 6"

aren't appropriate alternative hypotheses, because you make a statement about the sample rather than the population.

The correct H1 in the two-tailed case is

H1: the probability of success is not 0.6, i.e. p != 0.6

With the H1s you gave above, your implicit null hypothesis is

H0: there will be exactly 6 successes in a sample

which you can refute with 100% certainty if you observe != 6 successes in any sample.

Perhaps Unit 2 of the SIGIL course, which tries to explain the logic behind the binomial test in detail, might help you get a better understanding of the procedure.  Slides are freely available here:

http://www.stefan-evert.de/SIGIL/sigil_R/

Alternatively, read any good introductory statistics textbook that includes the exact binomial test.

> (3) What is people's view on computing the two-tailed test like this,
> which leads to an ns result unlike binom.test?
> 2*sum(dbinom(51:235, 235, 1/6)) # 0.05308849

This is a popular approximation (which I also use most of the time) because it's much less expensive (in computational terms) than computing an exact (likelihood-based) two-tailed p-value as binom.test() does.  This is particularly relevant if you want to compute confidence intervals for the true probability p based on a large sample, which takes ages with binom.test().

Hope this helps,
Stefan
```