If I would like to test separately withing each group that is there a significant difference in distribution among categories (C1-C4).

Apologies if I go back to the very core of your main question, but I do not fully understand the reason why you may want to "modify" the chi-sq test when it actually proves fit to your situation.

What I mean is that chi-sq test is meant to test if a significant association exists between the levels of two categorical variables, i.e. between your table's row and column categories. So, the chi-sq test (of independence) will address this question, provided that this very question is the one you wish to investigate.

Also, should the "regular" chi-sq test prove significant, a usual follow-up test would entail calculating the standardized residuals for each cell. They will help you locating which cells is significantly contributing to the rejection of the Null Hypothesis of independence, i.e. where there is a significant "connection" (either positive or negative) between the levels of the two categ. variables.

See for example the following small cross-tabulation (taken from literature) of Univ. faculty vs funding categories:

Code:

```
A B C D E
Geology 3 19 39 14 10
Biochemistry 1 2 13 1 12
Chemistry 6 25 49 21 29
Zoology 3 15 41 35 26
Physics 10 22 47 9 26
Engineering 3 11 25 15 34
Microbiology 1 6 14 5 11
Botany 0 12 34 17 23
Statistics 2 5 11 4 7
Mathematics 2 11 37 8 20
```

The chi.sq test is significant (p: <0.01). The table of standardized residuals (see attached .jpg, and focus on absolute values larger than 1.96) indicates that there is a negative association between Geology and funding catefory E (i.e., the observed frequency for Geology in category E is less than expected under the hypothesis of independence). ON the other hand, Zoology has a "positive" connection with funding category D, Physics with A, Engineering with E.

Hope this helps

Gm