Skip to content

Chi-squared test when observed near expected

5 messages · Troy S, William Dunlap, (Ted Harding) +2 more

#
Read about Yate's continuity correction - your formula does not use it
and chisq.test does unless you suppress it:

  > chisq.test(trial)  
  
          Pearson's Chi-squared test with Yates' continuity correction

  data:  trial 
  X-squared = 0, df = 1, p-value = 1
  
  > chisq.test(trial, correct=FALSE)

          Pearson's Chi-squared test

  data:  trial 
  X-squared = 0.0556, df = 1, p-value = 0.8136


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
#
On 03-Dec-2012 21:40:35 Troy S wrote:
being zero in this case?
The reason is that (by default, see ?chisq.test ) the statistic
is caluclated using the "continuity correction" (1/2 is subtracted
from each abs(O-E) difference). The default setting in chisq.test()
is "correct = TRUE". Try it with "correct = FALSE":

  x0<-chisq.test(trial,correct=FALSE)
  x0
  #      Pearson's Chi-squared test
  # data:  trial 
  # X-squared = 0.0556, df = 1, p-value = 0.8136

which agrees with your calculation of

  sum((x$observed-x$expected)^2/x$expected)
  # [1] 0.05562457

Hoping this helps,
Ted.

-------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at wlandres.net>
Date: 03-Dec-2012  Time: 22:44:14
This message was sent by XFMail
#
On Dec 3, 2012, at 1:40 PM, Troy S wrote:

            
... after rounding you say?
If  O==E that sum would be identically 0 if the conditions stated  
held ...  which they do NOT for the case below.
David Winsemius, MD
Alameda, CA, USA
#
When you typed x as a command, R runs the command print(x). That function
produces a summary of the results which may include round off numbers to a
few decimal places to make them more readable. When you typed x$statistic,
you got the unrounded version of the result 5.6e-31 which I think you will
agree is pretty close to 0.

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352