Pearsons's Chi-Square Test of Independence tests the independence between two categorical variables, \(x\) and \(y\) which contain \(s\) and \(r\) categories respectively. The test statistic is:
\[\begin{align} X^2 = \sum^s_{k=1}\sum^r_{j=1} \frac{(o_{kj} - e_{kj})^2}{e_{kj}} \end{align}\]
where:
\(o_{kj} = \sum^n_{i=1} w_i I_{x=k,y=j},\)
\(w_i\) is the Calibrated Weight of the \(i\)th of \(n\) observations,
\(e_{kj} = \frac{\sum^s_{k=1} o_{kj} \times \sum^r_{j=1} o_{kj}}{ \sum^n_{i=1} w_i}\)
\(p \approx \Pr(\chi^2_{(s-1)(g-1)} \ge X^2)\)