# chi sq post hoc analysis

I ran a chisq.test for group (3 levels) and Age (3 levels) which came back as significant. I am trying to figure out how to run some post-hoc tests to see where the significance lies. I am not sure if what I did next was correct.

data
Age
group  1    2   3
1     76   89  127
2     149  132 155
3     106  77  61

age_18_39 = smsDatraw$FM_diag_groups ==1 group_age_18_39 = smsDatraw[age_18_39, ]$agegroup==1
describe(group_age_18_39)

group_age_18_39
n=292 missing=860 distinct=2
value       FALSE    TRUE
Frequency   216      76
Proportion  0.74     0.26


I have repeated this step for each of the groups and age categories so I essentially have 9 individuals numbers.

t.test(group_age_18_39, group_age_18_39_2) #comparing group 1 and 2 for age 18-39


I would like to see where the differences lie and I am not sure what to do next. I originally tried a t.test but as it is categorical data I am assuming this isn't correct.

I am hoping I am over complicating this and there is a very simple solution, I just can't see.

Thank you so much to anyone who can help.

The $$\chi^2$$ test is a test of independence of factors group and age. If you reject the null, which you seem to do, then the factors are not independent, which means that knowledge of at least one factor value, e.g., age=2 or group=1 will help you at least narrow down your prediction of the value of the other factor. For instance, such knowledge could be as vague as knowing Factor $$Age=1$$ means that $$p(Group=2)$$ is, say, depressed compared to its background frequency. All it takes is one such relationship to be predictable for the null to be rejected.
To sort them out, you can calculate $$Z(g,a) = \left(N_{obs}(g,a)-N_{exp}(g,a)\right)/se(g,a)$$ for all 9 cases, where $$se(g,a)= \sqrt{N_{exp}(g,a)}$$ is the expected probability under the null hypothesis. Clearly, your most extreme $$Z$$ values will be your results from the post hoc. Where you cut off your post hoc depends on your favorite post hoc method: Bonferroni, Scheffe, etc.
• I've updated the result to give the correct standard error $se(g,a)$. Mar 12, 2019 at 1:44