Re: [R] In chisq.test(x) : Chi-squared approximation may be incorrect

From: David Winsemius <>
Date: Wed, 16 Jan 2008 04:33:09 +0000 (UTC)

"My Coyne" <> wrote in

> I received the following warning when running chi-square;
> n Is there a way to catch the 'error' code of 'warning' after run
> chisq.test(x)?

It is not an error message. It is a warning message. When I assign the result of chisq.test(.) to an object and then look at its structure with str(), I do not see the warning message "in there". Instead the message appears on the console. When you look at the chisq.test function itself you see that any "E" less than 5 will trigger the warning:

if (any(E < 5) && is.finite(PARAMETER))

        warning("Chi-squared approximation may be incorrect")

You should be able to check the <object>$expected matrix in a similar manner if you goal is to process a large number of tables programatically.

> n What does this error mean?

See above. Consider invoking chisq.test with the simulate.p.value option.

David Winsemius

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 16 Jan 2008 - 04:39:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 Jan 2008 - 07:30:06 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive