# Pearson's Chi-Square Test of Independence

Pearsons's Chi-Square Test of Independence tests the independence between two categorical variables, ${\displaystyle x}$ and ${\displaystyle y}$ which contain ${\displaystyle s}$ and ${\displaystyle r}$ categories respectively. The test statistic is
${\displaystyle X^{2}=\sum _{k=1}^{s}\sum _{j=1}^{r}{\frac {(o_{kj}-e_{kj})^{2}}{e_{kj}}}}$
${\displaystyle o_{kj}=\sum _{i=1}^{n}w_{i}I_{x=k,y=j}}$,
${\displaystyle w_{i}}$ is the Calibrated Weight of the ${\displaystyle i}$th of ${\displaystyle n}$ observations,
${\displaystyle e_{kj}={\frac {\sum _{k=1}^{s}o_{kj}\times \sum _{j=1}^{r}o_{kj}}{\sum _{i=1}^{n}w_{i}}}}$
${\displaystyle p\approx \Pr(\chi _{(s-1)(g-1)}^{2}\geq X^{2})}$