2 x 2 chisq.test (PR#8415)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

2 x 2 chisq.test (PR#8415)

cig69410
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: 2 x 2 chisq.test (PR#8415)

Brian Ripley
This is the same as PR#8265, from a person also not giving his/her name
but sharing your ISP.  Please don't submit a repeat, as the FAQ asks.

After last time this was raised, I checked Yates' original paper and
Fisher's book and it seems that R's formula follows what they say.

Do remember that 0 is an impossible value for a chisq-distributed
variable, and so one would not expect the corrected distribution to take
that value with positive probability.

On Tue, 20 Dec 2005 [hidden email] wrote:

> Full_Name: nobody

Do you expect us to take the word of `nobody' as to the correct definition
of a statistic?  We need your credentials and references.

> 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

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: 2 x 2 chisq.test (PR#8415)

Thomas Lumley
In reply to this post by cig69410

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, [hidden email] 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
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

Thomas Lumley Assoc. Professor, Biostatistics
[hidden email] University of Washington, Seattle

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel