Hi Jonothan,

After a little research, maybe a simpler way to implement a post-hoc test for a khi² test would be to use the existing chisq.test from the stats package which gives the khi² value, its significance level and the Pearsons' residues (Xsq$residuals) and the Habermans' residues (Xsq$stdres) ?

Example.

> M <- as.table(rbind(c(212,29,11,2,3), c(318,61,6,11,13), c(160,39,9,6,12)))

> rownames(M) <- c("a1","a2","a3")

> colnames(M) <- c("b1","b2","b3","b4","b5")

> M

b1 b2 b3 b4 b5

a1 212 29 11 2 3

a2 318 61 6 11 13

a3 160 39 9 6 12

> Xsq <- chisq.test(M)

Message d’avis :

In chisq.test(M) : l’approximation du Chi-2 est peut-^etre incorrecte

> Xsq

Pearson’s Chi-squared test

data: M

X-squared = 20.3583, df = 8, p-value = 0.009062

> Xsq$residuals

b1 b2 b3 b4 b5

a1 0.93616090 -1.33963261 1.28206096 -1.48489514 -1.78406400

a2 0.09113804 0.24066234 -1.71501389 0.77521492 0.04505463

a3 -1.12090876 1.10480426 0.93998072 0.54059524 1.84188135

> Xsq$stdres

b1 b2 b3 b4 b5

a1 2.33159333 -1.71672778 1.54215391 -1.77896194 -2.14848117

a2 0.26026470 0.35362027 -2.36537490 1.06489378 0.06221195

a3 -2.72597782 1.38245439 1.10404745 0.63240142 2.16587067

The khi² value gives 1% so every value of Xsq$stdres which sits outside [-2.33;+2.33] flags a significant difference. So here, the signficant differences are found between (a1, b1), (a2, b3) and (a3, b1).

The example comes from

http://www.normalesup.org/~carpenti/Not ... esidus.pdf (written in french, sorry). And the 2.33 limit comes from

http://www1.udel.edu/FREC/ilvento/FREC408/normhandI'm not a khi2 specialist at all, so it's just a suggestion. If a stats wizard would be kind enough to step in, his or her advices would be much appreciated

Have a nice day.