The chi-square test of independence checks whether two categorical variables are associated by comparing observed counts in a contingency table with the counts expected if they were independent. For an r × c table it has (r − 1)(c − 1) degrees of freedom; expected counts should not be too small.
Formula
χ² = Σ (O − E)² / E