Rounding error R binom.test?

Im confused by binom.test.

Let's say I want to test a 4/10 success pattern against p = 0.5. The value of P 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 sample 95/150 against p = 0.66. Here the expected value is 99, so the value of P should be

P (X <= 95) + P (X> = 103) or P (X <= 95) + 1-P (X <= 102)

which the

>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 values ​​of P is exactly equal dbinom(103,150,.66). So it seems that R did not include X = 103.

The only explanation I can guess is that there is a rounding error due to an inaccurate .66 representation causing R to simply skip X = 103. Is that all, or is there something else?

+4
1

p- binom.test(x = 95, n = 150, p = 0,66)

relErr <- 1 + 1e-07
d <- dbinom(x, n, p)
m <- n * p
i <- seq.int(from = ceiling(m), to = n)
y <- sum(dbinom(i, n, p) <= d * relErr)
pbinom(x, n, p) + pbinom(n - y, n, p, lower.tail = FALSE)

, binom.test . C, , C , C x , fudge relErr. , , , p - " , ", , p - , , .

dbinom(95,n,p)

0,05334916. , binom.test x, dbinom (x, n, p) 0,05343416. , 0:95 104: 150. , binom.test

sum(dbinom(0:95,n,p)) + sum(dbinom(104:150,n,p))

0,4914044.

+4

Source: https://habr.com/ru/post/1661262/


All Articles