I have to make a chi square test of two physical variables with R. I’am trying with:
Library('MASS')
Library('gplots')
data<-read.table('data.dat',head=F)
pp<-hist2d(data$V2,data$V3)
chisq.test(pp$counts)
but R says me:
Pearson's Chi-squared test
data: pp$counts
X-squared = NaN, df = 240, p-value = NA
I have used this script in past to performs chi square but now it does not work. where is the problem?
hist2dbins the data, but if some of the bins are always empty,the chi squared statistic is not defined (because of a division by zero).
You can try to reduce the number of bins,
or discard the bins that are empty.
(From a statistical point of view,
I am not sure that what you are doing is optimal.)