[R] binom.test inside ctest

Emmanuel Paradis paradis at isem.univ-montp2.fr
Tue Sep 12 09:49:06 CEST 2000


At 00:22 12/09/00 -0400, you wrote:
>I got 
>
>binom.test(65, 100, p=0.5)
>
>
>p-value = 0.002654
>
>I thought in this case (when p=0.5 so a symmetric distribution)
>we should get 
>
>p-value = 2*( 1-pbinom(64, 100, p=0.5) ) = 0.003517642
>
>Can somebody explain why the difference?
>
>Thanks.
>
>Mai Zhou

Hi,

When looking in the R code (in RHOME/library/ctest/R/ctest), you can see
that the p-value is computed like this:

> ( 1-pbinom(64, 100, p=0.5) ) + pbinom(34, 100, p=0.5)
[1] 0.002653786

The relevant bit of code is:

                           ## Do
                           ##   d <- dbinom(0 : n, n, p)
                           ##   sum(d[d <= dbinom(x, n, p)])
                           ## a bit more efficiently ...
                           d <- dbinom(x, n, p)
                           if(x / n < p) {
                               i <- seq(from = x + 1, to = n)
                               y <- sum(dbinom(i, n, p) <= d)
                               pbinom(x, n, p) +
                                   (1 - pbinom(n - y, n, p))
                           } else {
                               i <- seq(from = 0, to = x - 1)
                               y <- sum(dbinom(i, n, p) <= d)
                               pbinom(y - 1, n, p) +
                                   (1 - pbinom(x - 1, n, p))
                           }
 

Emmanuel Paradis
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list