Comparison of observed and estimated cell counts

We test for independence with the hypotheses:

H0 :  X and Y are independent
HA :  X and Y are dependent  

The test asks whether the observed and estimated cell counts are 'sufficiently close' — are the observed counts consistent with the counts estimated under independence?

Observed and estimated cell counts
     Male     Female  Total
A 20
(11.59)
60
(68.41)
80
B 9
(13.47)
84
(79.53)
93
C 2
(5.94)
39
(35.06)
41
Total 31 183 214

Possible test statistic?

A simple summary of how close the observed counts, nxy, are to the estimated cell counts, exy, is the sum of the squared differences,

Unfortunately this would be a bad test statistic — its distribution depends not only on the numbers of rows and columns in the table, but also on the number of individuals classified — the overall total for the table. A better test statistic is presented in the next page.