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

David Winsemius dwinsemius at comcast.net
Wed Jan 16 05:33:09 CET 2008

"My Coyne" <mcoyne at boninc.com> 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 

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 

> n  What does this error mean?

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

David Winsemius

More information about the R-help mailing list