# Chi-square test: difference between goodness-of-fit test and test of independence

Concerning the Pearson chi-square test there seems to be a subtle difference between the goodness-of-fit test and the test of independence.

What is confusing is that both tests seem to be calculated in a very similar way.

My question: What is the real difference and how to handle that in practice?

(NB: This is question is related, yet not the same: Test of independence vs test of homogeneity)

• Note chisq.test performs one or the other depending on its arguments - read the manual. – Scortchi Mar 31 '14 at 7:31
• @Scortchi: Edited the question accordingly - thank you. – vonjd Mar 31 '14 at 8:25

## 1 Answer

1) A goodness of fit test is for testing whether a set of multinomial counts is distributed according to a prespecified (i.e. before you see the data!) set of population proportions.

2) A test of homogeneity tests whether two (or more) sets of multinomial counts come from different sets of population proportions.

3) A test of independence tests is for a bivariate** multinomial, of whether $p_{ij}$ is different from $p_{i}\,p_{j}$.

**(usually)

Sometimes people make the mistake of treating the second case as if it were the first. This underestimates the variability between the proportions. (If one sample is very large the error in treating it as population proportions will be relatively small.)