I am trying to understnad where this formula comes from:

My first guess was that it has something to do with dimensions of subspaces, since for a goodness of fit test there is a system of equations "hidden" in a contingency table, I think. I found the following, unfortunately without proof.
Is there a book with a proof?
Furthermore I woud like to understand what is going on here http://fisher.stats.uwo.ca/faculty/kulperger/SS3858/Handouts/ContingencyTables.pdf .
This looks like multi-dim. random variables. Could the contigency table be considered as as a vector? Just as a mtarix can be identified with a vector in $\mathbb{R}^{n^2}$?
Many thanks in advance.
