Solution (source code)

= Solution
{c}

Let $N_{ij}$ be the observed cell counts, $N_{i+}$ the row totals, $N_{+j}$ the column totals and $N=33009$. The fitted <expected frequencies> under <independence> are $E_{ij}=N_{i+}N_{+j}/N$. For example the three-child, one-boy cell has expected count $7541\cdot16472/33009=3763.1$.

The <Pearson chi-squared statistic> is
$$
\boxed{X^2=\sum_{i=1}^2\sum_{j=1}^3\frac{(N_{ij}-E_{ij})^2}{E_{ij}}.}
$$
Under $H_0$ it has asymptotically a <chi-squared distribution> with $(2-1)(3-1)=2$ degrees of freedom, assuming the multinomial sampling model and sufficiently large expected counts. All expected counts here are large. The distribution is an asymptotic approximation, rather than an exact finite-sample identity.