# Can you use the chi-squared test to test difference between two already observed groups?

I have conducted a survey regarding the age range of both customers and non-customers of a particular restaurant. The results can be seen below:

| 25  | 26-40  |   42-65 |   65+  | Total
Customers         | 17  |   79   |     68  |   10   |  174
Non Customers     | 21  |   41   |     65  |   17   |  144

I would like to determine if there is any difference among the two groups regarding age. And in particular which age ranges seem to be significantly different. However, im just confused as to how to come up with expected values.

Glen_b's answer on Can you use the chi-squared test when the expected values are not determined? helped me, however, I'm still confused as to how I would find out if there is a significant difference in an individual age range, as opposed to an overall difference.

If for example, the observed value was 1, and expected 2, would I simply do ((1 - 2) ^2)/2 and use a df of 1?

• What's wrong with a chi-square test of independence for the contingency table presented in your question? – Mike Hunter Apr 3 '17 at 19:05
• I don't understand the distinction you're making regarding "already observed groups". – gung - Reinstate Monica Apr 3 '17 at 19:15
• You're not sufficiently clearly explaining what you want. If you're trying to find where the bigger deviations from expected are you could look at the $(o_i-e_i)/\sqrt{e_i}$ values (whose squares are contributions to chi-square), or you can look at binomial standardized residuals (which are a bit larger); this sort of calculation would be a common thing to do after a chi-square. If you're specifically looking at age-by-age comparisons you can do two sample proportions tests (which should correspond to 2x2 chi-squared of that age out of the rest) ... but you'll be doing 4 tests just for that – Glen_b Apr 3 '17 at 22:07

## 1 Answer

For the purposes of a chi-squared test, the expected value for each cell is the (column total) * (row total) / (total). For example, the expected value of your customers 26-40 cell is 120 * 174 / 318 = 65. Continuing, you will find a chi-squared value for the whole table of 11.61, with a P-value of 0.0088, indicating that there is a definite difference in the age profile between customers and non-customers.

For a heuristic view of which cells are the "most off", by all means compute z = (observed n - expected n ) / sqrt(expected n) for each cell and look at the cells with the biggest |z|. But don't expect this to have a strict probability interpretation under some null hypothesis for the cell. The fact that the cells must sum in specific ways imposes constraints that don't allow them to be treated independently.