[R] chisq.test freezing on certain inputs
Torsten Hothorn
Torsten.Hothorn at rzmail.uni-erlangen.de
Thu Dec 11 18:01:40 CET 2003
On Thu, 11 Dec 2003, Jeffrey Chang wrote:
> Hello everybody,
>
> I'm running R 1.8.1 on both Linux and OS X compiled with gcc 3.2.2 and
> 3.3, respectively. The following call seems to freeze the interpreter
> on both systems:
> > chisq.test(matrix(c(233, 580104, 3776, 5786104), 2, 2),
> simulate.p.value=TRUE)
>
> By freeze, I mean, the function call never returns (running > 10 hours
> so far), the process is unresponsive to SIGINT (but I call kill it with
> TERM), and the process still consumes cycles on the CPU.
>
This is due to calling `exp' with a very small value leading to
a zero return value in rcont2 (src/appl/rcont.c) line 70:
x = exp(fact[iap - 1] + fact[ib] + fact[ic] +
fact[idp - 1] - fact[ie] - fact[nlmp - 1] -
fact[igp - 1] - fact[ihp - 1] - fact[iip - 1]);
if (x >= dummy) {
goto L160;
}
sumprb = x;
y = x;
y is never checked for zero and later on
L150:
if (lsm) {
goto L155;
}
/* Decrement entry in row L, column M */
j = nll * (ii + nll);
if (j == 0) {
goto L154;
}
--nll;
y = y * j / (double) ((id - nll) * (ia - nll));
sumprb += y;
if (sumprb >= dummy) {
goto L159;
}
if (! lsp) {
goto L140;
}
goto L150;
y has no chance of becoming larger than zero and we are in the goto trap
until the end of time. A simple fix would be checking for zero but I don't
know how one would proceed in this case ...
Best,
Torsten
More information about the R-help
mailing list