# chi-square test of independence

I am trying to do a chi-square test of independence on two samples of counts. You can download the data from here (just click the "download" button):

Sample 1 and sample 2 are from different populations. You should just treat them as two categories. For the first csv file, I ran chisq.test in R on sample1 and sample2 directly.

chisq.test(chi.test1, simulate.p.value=T)


and the result is the Null hypothesis rejected:

Pearson's Chi-squared test with simulated p-value (based on 2000 replicates)
data:  chi.test1
X-squared = 6067.4, df = NA, p-value = 0.0004998


However, if I ran the same test on the second .csv file, where I compare sample1 with the sum of sample 1 and sample 2. Then the null cannot be rejected and p-value is 1. I got the same results if I compare sample2 and the sum.

Pearson's Chi-squared test with simulated p-value (based on 2000 replicates)
data:  chi.test2
X-squared = 3948.316, df = NA, p-value = 1


The results here seem counter-intuitive: if the distribution is independent of the sample we choose, why would we obtain different results when we use combinations of samples? And how do we interpret the results? It seems that I made a mistake here but I don't know what exactly it is.

## migrated from stackoverflow.comMar 8 '15 at 22:27

This question came from our site for professional and enthusiast programmers.

• hi this isn't really R related, but rather a statistics question. i'm voting to move this over to the stats stackexchange where you may receive better help. – bjoseph Mar 7 '15 at 17:36

By using sample 1 twice, you induce dependence between your two groups, but then you used a procedure that assumes they're independent.

It's hardly surprising, then, that you get a different result when you violate an important assumption and don't modify the procedure to account for that change.