how is chi square test interpreted for cross tables? Stats newbiew here.
I understand that I use the chi square test to be able to calculate the probability that an observed value is due to chance against an expected value. I understand that it can be described as a quantification of how much the observed value differs from the expected one.
How does that apply to crosstables? 
Is it simple a combinded quantification (e.g. what is expected in both groups on a two dimensional crosstab) or does it say something about the correlation of the groups in a crosstable? What does the degree of freedom has to do with that?
 A: Setting. In a cross classification with $r$ rows and $c$ columns, the
usual null hypothesis for a chi-squared test is that the
row categorical variable with $r$ levels is $independent$ of the 
column categorical variable with $c$ levels.
Finding expected cell counts to match 'independence'. The task is to find expected counts $E_{ij}$ for each of the $rc$
cells in the table, which may be compared with the corresponding
observed counts $X_{ij},$ for $i = 1, 2, \dots, r$ and
$j = 1, 2, \dots, c.$
Suppose that the total count in row $i$ is $R_i = \sum_{j=1}^c X_{ij},$ that the total count in column $j$ is $C_j = \sum_{i=1}^r X_{ij}$ 
and that the grand total of all $rc$ counts in the table
is $$G = \sum_i \sum_j X_{ij} = \sum_i R_i = \sum_j C_j.$$
Our estimate of the probability of the $i$th level of the row
variable is $\hat P_{i} = R_i/G.$ Similarly, our estimate of the probability of 
the of the $j$th level of the column variable is $\hat Q_j = C_j/G.$
Then, using the independence assumed in the null hypothesis,
our estimate of the probability of falling into cell $(i,j)$ is
the product $\hat P_{ij} = 
\hat P_i \hat Q_j = R_i C_j/G^2.$ (The idea is that, under
independence, $P_{ij} = P_iQ_j$. So their estimates should
also multiply.)
From this independence-based estimate $\hat P_{ij},$
we obtain the expected number in cell $(i,j)$ as 
$\hat \mu_{ij} = E_{ij} = G\hat P_{ij} = R_iC_j/G.$ (This is similar to $\mu = np$
for the binomial mean.)
The chi-squared statistic. Now the chi-squared goodness-of-fit statistic (to independence
of row and column categorical variables) is the total
$$T = \sum_i \sum_j \frac{(X_{ij} - E_{ij})^2}{E_{ij}},$$
which has approximately a chi-squared distribution with
degrees of freedom $df = (r-1)(c-1),$ provided that all of
the expected cell means $E_{ij} > 5.$
Degrees of freedom. To illustrate the reason that $df = (r-1)(c-1),$ consider
an simple example with $r = 2$ and $c = 3$. The table
has only $(r-1)(c-1) = 2$ of the $X_{ij}$ filled in,
along with the marginal totals.
 j \  i    1   2   3     Total
 -----------------------------
 1        11  23          50
 2                       100           
 -----------------------------
 Total    32  78  40     150

Notice that, given the marginal totals and these $df = 2$
values, it is possible to fill in the remaining $X_{ij}.$
It is examples such as this one that give rise to the
terminology 'degrees of freedom' and the formula $df = (r-1)(c-1).$ 
Addendum: To help you practice formulas, start by filling in
missing $X_{ij}$ in the table above. Then find a few $E_{ij}$s
(do $not$ round to integer values).
Finally, find the chi-squared statistic (add up the six
contributions) and do the test (5% level)
for independence. Minitab results pasted below. What is the
'critical value' (from a printed chi-sq table) for a test at the 5% level?
 Expected counts are printed below observed counts
 Chi-Square contributions are printed below expected counts

               1      2      3  Total

        1     11     23     16     50
           10.67  26.00  13.33
           0.010  0.346  0.533

        2     21     55     24    100
           21.33  52.00  26.67
           0.005  0.173  0.267

    Total     32     78     40    150

    Chi-Sq = 1.335, DF = 2, P-Value = 0.513

