## How do I perform a chi-square test?

## Answer

There are actually multiple types of chi-square test. The two we will focus on are the chi-square test for homogeneity and the chi-square test for independence (also sometimes called the test for association). Both tests require two categorical variables; the difference lies in what we are testing for and the characteristics of the underlying population(s).

In a chi-square test for homogeneity, we are comparing whether two distinct populations have the same distribution. The null hypothesis is that the two populations have the same distribution, and the alternative hypothesis is that they have different distributions. For example, we would use a test for homogeneity to determine if the distribution of cat ownership is different between the male and female populations.

In a chi-square test for independence, we are testing the relationship between two variables within one population. The null hypothesis is that the two variables are independent (not related) and the alternative hypothesis is that they are dependent (related) For example, we would use a test for independence to test whether people who own a dog are more likely to also own a cat.

While the hypotheses and conclusions for these tests are different, the results are calculated using the same formula:

\[X_c^2 = \frac{\sum (O_i - E_i)^2}{E_i}\]

The chi-square statistic is found using the difference between the observed value Oi and the expected value Ei for each entry in the contingency table. A p-value can also be calculated to determine the statistical significance of the result.