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

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Dec 9 15:37:55 CET 2003


Marc Schwartz <MSchwartz at medanalytics.com> writes:

> Confirmed on Fedora Core 1 with R Version 1.8.1 Patched (2003-12-07)
> compiled using "gcc (GCC) 3.3.2 20031107 (Red Hat Linux 3.3.2-2)".
> 
> 
> > chisq.test(matrix(c(0, 1, 1, 12555), 2, 2), simulate.p.value=TRUE)
> ...
> X-squared = 1e-04, df = NA, p-value = 1
> 
> > chisq.test(matrix(c(0, 1, 1, 12556), 2, 2), simulate.p.value=TRUE)
> 
> 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)
> ...
> X-squared = 1e-04, df = NA, p-value = 1

Ditto on RH8 with Martyn's RPM of 1.8.0 (yeah, I know...) and ditto
with a reasonably current r-devel (gcc 3.2)

Anyways, it is yet another fudge-factor issue: If you debug to the
point in chisq.test where it calculates

PVAL <- sum(tmp$results >= STATISTIC)/B

you'll find that

Browse[1]> any(diff(tmp$result))
[1] FALSE
Browse[1]> tmp$result[1]
[1] 7.96432e-05
Browse[1]> STATISTIC
[1] 7.96432e-05
Browse[1]> tmp$result[1] - STATISTIC
[1] -1.355253e-20

so PVAL becomes zero and yaddayaddayadda....

The obvious fix would seem to be

PVAL <- sum(tmp$results >= (1-1e-10)*STATISTIC)/B
.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list