# Current chi-square test of homogeneity POST HOC analyses in R

I am looking for a currently-working method of running a chi-square post hoc test.

I've run a chi-square test of homogeneity using chisq.test from stats, however, I am at a loss when it comes to suitable post hoc tools. People recommend FIFER package, however, how do I make it suitable for a homogeneity test?

Can someone please point me in the right direction. I am fairly new to chi squares and R, so apologies if I'm missing something obvious.

My data is contracted as 3 groups (rows) x 5 categories (columns).

• sorry, yes, Edited question Commented Oct 7, 2019 at 9:56
• stats, lower case. Case matters in this .... er, case. MASS is all caps (since it's an acronym) but most names of packages distributed with R are all small letters. Commented Oct 7, 2019 at 9:58

As stated here, you can modify the chisq.testto compute partial X2 statistics for rows or columns. Then you can get the corrected p-values with p.adjust for bonferroni or other corrections.

nr <- as.integer(nrow(x))
nc <- as.integer(ncol(x))
n=sum(x)
sr <- rowSums(x)
sc <- colSums(x)
E <- outer(sr, sc, "*")/n
dimnames(E) <- dimnames(x)

STATISTIC <- sum((abs(x - E) )^2/E)
PARAMETER <- (nr - 1L) * (nc - 1L)
PVAL <- pchisq(STATISTIC, PARAMETER, lower.tail = FALSE)
cat("X-squared =",PARAMETER,", df=",PARAMETER, ", p-value =",PVAL)
(cell.chisq = (x - E)^2/E)

p=pchisq(rowSums(cell.chisq), df =  1,lower.tail = FALSE)