[R] binom.test()

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Mon Sep 23 17:50:01 CEST 2002


Peter Dalgaard BSA <p.dalgaard at biostat.ku.dk> writes:

> That would create different problems, I suspect. The main issue seems
> to be that this construct
> 
>                 i <- seq(from = 0, to = x - 1)
>                 y <- sum(dbinom(i, n, p) <= d * relErr)
>                 pbinom(y - 1, n, p) + pbinom(x - 1, n, p, lower = FALSE)
> 
> is assumed to give y somewhere in the left tail, but in this case we
> count some values in the right (i.e. wrong...) tail too. I'd expect
> that using something like 
> 
>                 i <- seq(from = 0, to = ceiling(n*p))
> 
> might work, but don't take my word for it...

This does seem to work:

                       else {
                           ## Do
                           ##   d <- dbinom(0 : n, n, p)
                           ##   sum(d[d <= dbinom(x, n, p)])
                           ## a bit more efficiently ...
                           ## Note that we need a little fuzz.
                           relErr <- 1 + 10 ^ (-7) 
                           d <- dbinom(x, n, p)
                           if(x / n < p) {
                               i <- seq(from = ceiling(n*p), to = n)
                               y <- sum(dbinom(i, n, p) <= d * relErr)
                               pbinom(x, n, p) +
                                   pbinom(n - y, n, p, lower = FALSE)
                           } else {
                               i <- seq(from = 0, to = floor(n*p))
                               y <- sum(dbinom(i, n, p) <= d * relErr)
                               pbinom(y - 1, n, p) +
                                   pbinom(x - 1, n, p, lower = FALSE)
                           }
                       }

If anyone can think of a reason why this might be wrong, please speak
up before I put this into R-1.6.0!

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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