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

Jeffrey Chang jeffrey.chang at duke.edu
Tue Dec 9 17:21:26 CET 2003


On Dec 9, 2003, at 9:37 AM, Peter Dalgaard wrote:

> 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

Yes, this is also the behavior that I am seeing.  I do not know about 
numerical programming to comment on the fix, but it would solve the 
problem in my case.

Thanks to everyone who has looked into this!

Jeff




More information about the R-help mailing list