I’m confused about the operation of binom.test.
Say I want to test a sample of 4/10 success against p=0.5. The P value should be:
P(X <= 4) + P(X >=6) or P(X <= 4) + 1-P(X <= 5)
and indeed:
>pbinom(4,10,p=0.5) + 1-pbinom(5,10,0.5)
[1] 0.7539063
or:
>binom.test(4,10,p=0.5)
Exact binomial test
data: 4 and 10
number of successes = 4, number of trials = 10, p-value = 0.7539
But now I want to test a sample of 95/150 against p=0.66 Here, the expected value is 99, so the P value should be
P(X <= 95) + P(X >= 103) or P(X <= 95) + 1-P(X <= 102)
which is
>pbinom(95,150,.66) + 1-pbinom(102,150,.66)
[1] 0.5464849
but
>binom.test(95,150,.66)
Exact binomial test
data: 95 and 150
number of successes = 95, number of trials = 150, p-value = 0.4914
In fact, the difference in the two P-values is exactly dbinom(103,150,.66)
. So it seems R has failed to include X=103.
The only explanation I can guess for this is that there is roundoff error due to the inexact representation of .66 causing R to just miss X=103. Is this all it is, or is there something else going on?