Pearson chi-squared test of independence (source code)

= Pearson chi-squared test of independence
{c}

For an $r$ by $c$ contingency table, the statistic
$$
X^2=\sum_{i,j}\frac{(O_{ij}-E_{ij})^2}{E_{ij}}
$$
has asymptotically a chi-squared distribution with $(r-1)(c-1)$ degrees of freedom under independence.