[R] p-value from chisq.test working strangely on 1.8.1

Jeffrey Chang jeffrey.chang at duke.edu
Tue Dec 9 04:53:10 CET 2003


Hello everybody,

I'm seeing some strange behavior on R 1.8.1 on Intel/Linux compiled  
with gcc 3.2.2.  The p-value calculated from the chisq.test function is  
incorrect for some input values:


 > chisq.test(matrix(c(0, 1, 1, 12555), 2, 2), simulate.p.value=TRUE)

         Pearson's Chi-squared test with simulated p-value (based on 2000
         replicates)

data:  matrix(c(0, 1, 1, 12555), 2, 2)
X-squared = 1e-04, df = NA, p-value = 1

 > chisq.test(matrix(c(0, 1, 1, 12556), 2, 2), simulate.p.value=TRUE)
[...]
data:  matrix(c(0, 1, 1, 12556), 2, 2)
X-squared = 1e-04, df = NA, p-value = < 2.2e-16

 > chisq.test(matrix(c(0, 1, 1, 12557), 2, 2), simulate.p.value=TRUE)
[...]
data:  matrix(c(0, 1, 1, 12557), 2, 2)
X-squared = 1e-04, df = NA, p-value = 1


In these three calls to chisq.test, I'm varying the input matrix by  
only 1 observation, but the p-value changes by 16 orders of magnitude.   
This is reproducible on my system.  Please let me know if any other  
information would be useful.

chisq.test works properly for these inputs on Mac OS X 10.3.1 with R  
1.8.0.  I don't know if the problem is with Linux or 1.8.1.

This bug looks very similar to bug 4718, which was reported in R 1.8.0  
and fixed in R 1.8.1.  They may be related.
http://r-bugs.biostat.ku.dk/cgi-bin/R/Analyses-fixed?id=4718; 
user=guest;selectid=4718

Jeff




More information about the R-help mailing list