The chi-squared statistic (\( \chi^2 \)) is calculated using the formula: \[ \chi^2 = \sum \frac{(O_i - E_i)^2}{E_i} \] where \( O_i \) is the observed frequency and \( E_i \) is the expected frequency for each category.
The expected frequency for each category is computed based on the assumption that there is no association between the variables (null hypothesis).