JSalazar
JSalazar

Reputation: 33

Chi square test error "Chi-squared approximation may be incorrect"

I ran a chi-squared test in R and the results are:

crianza = matrix(c(1,1,0,12,12,7,2,1,0,0,1,0,0,0,5,
      0,0,0,1,1,2,0,0,3,0,0,0,13,35,29,0,0,1,10,
      0,0,1,0,0,0,0,0),ncol=3,byrow=TRUE)
colnames (crianza) = c("Neonate","Juevenile","Adult")
rownames (crianza) = c("C.acronotus","C.limbatus","C.obscurus","C.perezi",
 "C.porosus","C.falciformis","G.cuvier","G.cirratum","M.canis",
 "R.porosus","R.lalandii","S.lewini","S.mokarran","S.tiburo")    
crianza = as.table(crianza)

Pearson's Chi-squared test

data:  crianza
X-squared = NaN, df = 26, p-value = NA

Warning message:
In chisq.test(crianza) : Chi-squared approximation may be incorrect

Does anyone know why it gave a warning? Is it because I am using a wrong method?

Upvotes: 3

Views: 15926

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226332

You're getting NA values because you have rows with no counts at all.

cc <- crianza[rowSums(crianza)>0,]
chisq.test(cc)

To circumvent the warning, try simulate.p.value=TRUE:

chisq.test(cc, simulate.p.value=TRUE)

Note that this as an extremely unbalanced table, with simulated p-values you will essentially get a value as small as 1/(number of simulations run):

chisq.test(cc, simulate.p.value=TRUE, B=1e6)

I got as far as B=1e7 before I ran out of patience. You should probably not worry about reporting values beyond "the p-value is very small, at most 1e-6"

Upvotes: 4

Related Questions