From ripley at stats.ox.ac.uk  Tue Dec 20 17:01:03 2005
From: ripley at stats.ox.ac.uk (ripley@stats.ox.ac.uk)
Date: Tue, 20 Dec 2005 17:01:03 +0100 (CET)
Subject: [Rd] 2 x 2 chisq.test (PR#8415)
Message-ID: <20051220160103.DFB7419A65@slim.kubism.ku.dk>

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 cig69410 at syd.odn.ne.jp 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,                  ripley at stats.ox.ac.uk
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



[Rd] 2 x 2 chisq.test (PR#8415)
ripley@stats.ox.ac.uk