What is the difference between the chi-squared test for independence and the chi squared test for homogeneity?
The independent test is used when there are 2 categorical variables from a single population.
The homogeneity test is used when there is only 1 categorical variable from 2 (or more) populations.
For example, in a university, students might be classified their gender (female or male) or by their primary major (mathematics, chemistry, history, etc.). We use a chi-square test for independence to determine whether gender is related to their choice of study.
In the chi-squared test of homogeneity, the data are collected by sampling each sub-group separately, to determine if the frequency count differed significantly across different populations.
For example, in a survey of subject preferences, we might ask students for their favorite subject. We ask the same question of two different populations, such as females and males. We then use a chi-square test for homogeneity to determine whether female subject preferences differed significantly from male subject preferences.
The difference lies in the design of the study.