[Rd] 2 x 2 chisq.test (PR#8415)

Thomas Lumley tlumley at u.washington.edu
Tue Dec 20 17:18:34 CET 2005


This is the same as PR#8265, which was reported two months ago by someone 
else from syd.odn.ne.jp.  It still isn't a bug. According to Brian 
Ripley's response at that time, "almost all" the sources he checked gave 
the correction that R uses.

 	-thomas

On Tue, 20 Dec 2005, cig69410 at syd.odn.ne.jp wrote:

> Full_Name: nobody
> Version: 2.2.0
> OS: any
> Submission from: (NULL) (219.66.34.183)
>
>
> 2 x 2 table, such as
>
>> x
>     [,1] [,2]
> [1,]   10   12
> [2,]   11   13
>
>> chisq.test(x)
>
> 	Pearson's Chi-squared test with Yates'
> 	continuity correction
>
> data:  x
> X-squared = 0.0732, df = 1, p-value = 0.7868
>
> but, X-squared = 0.0732 is over corrected.
>
> when abs(a*d-b*c) <= sum(a,b,c,d), chisq.value must be 0!, and P-value must be
> 1!
>
> code of chisq.test must be as follows
>
> #           if (correct && nrow(x) == 2 && ncol(x) == 2) {
> #               YATES <- 0.5
> #               METHOD <- paste(METHOD, "with Yates' continuity correction")
> #           }
> #           else YATES <- 0
> #           STATISTIC <- sum((abs(x - E) - YATES)^2/E)
> ## replace begin
>             if (correct && nrow(x) == 2 && ncol(x) == 2) {
>                 STATISTIC <- if (abs(x[1,1]*x[2,2]-x[1,2]*x[2,1]) < sum(x)/2) 0
>
>                              else sum((abs(x - E) - 0.5)^2/E)
>                 METHOD <- paste(METHOD, "with Yates' continuity correction")
>             }
>             else STATISTIC <- sum((abs(x - E))^2/E)
> ## replace end
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle



More information about the R-devel mailing list