3

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?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
JSalazar
  • 33
  • 1
  • 1
  • 4
  • This question is perhaps a better fit for the Cross Validated site - there is a [good existing answer](https://stats.stackexchange.com/questions/81483/warning-in-r-chi-squared-approximation-may-be-incorrect) there. – neilfws Oct 29 '18 at 23:00
  • 1
    Possibly related: https://stats.stackexchange.com/q/81483/60634, https://stats.stackexchange.com/q/155523/60634. If you look at the source for `chisq.test`, that message appears once, after `if (any(E < 5) && is.finite(PARAMETER))`, where `E` might be `n*p` or `outer(sr, sc, "*")/n`, depending on non-matrix or matrix input, respectively. – r2evans Oct 29 '18 at 23:00

1 Answers1

4

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"

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453