Assume a contingency table $I\times J$, which consists of counts of multinomial r.v. with $I$ categories from $J$ populations with fixed marginal totals $n_{\cdot j}=\sum^I_{i=1}n_{ij}$ for each population.
We can use the Pearson's Chi-square statistics to test for homogeneity:
$\chi^2=\sum^I\sum^J\dfrac{(O_{ij}-E_{ij})^2}{E_{ij}}=\sum^I\sum^J\dfrac{(n_{ij}-n_{i\cdot}n_{\cdot j}/n_{\cdot\cdot})^2}{n_{i\cdot}n_{\cdot j}/n_{\cdot\cdot}}$
The degrees of freedom should represent the number of independent variates in the model/statics used - in this case that would be Pearson's chi-square statistics.
In J. A. Rice's book, the following explanation is given for determining the dof:
The degrees of freedom are the number of independent counts minus the number of independent parameters estimated from the data. Each multinomial has $I-1$ independent counts, since the totals are fixed, and $I-1$ independent parameters have been estimated. The degrees of freedom are therefore $(I-1)(J-1)$.
However, I don't think that the counts are independent. Since the marginal counts $n_{\cdot j}$ are fixed, and the cell counts are nonnegative and must sum to $n_{\cdot j}$, they are not independent. Clearly, by setting arbitrary $n_{ij}$ (for some $j$) to some value (e.g. $n_{ij}=x$), the rest of the counts $n_{kj}$ for $k\neq i$ will be affected, as the maximum permissible value is now $n_{\cdot j}-x$.
I tried to search for the answer, but unfortunately, majority of the sites simply repeat the formula without any comment.
Where is the error in my reasoning? What am I misunderstanding about dof.