I have a question on categorical data -

I have a 2x4 matrix and I want to test the difference in the number of males or females in each group, and so I entered the data into R.

So I input this:


This is the output that I get -

Fisher's Exact Test for Count Data

data:  tab 
p-value = 0.01077
alternative hypothesis: two.sided

The only statistical information I get is the p-value - how do I know how the groups are different?


2 Answers 2


In a sense this is analogous to a situation where you test for differences in group means with ANOVA and then perform a post hoc test, such as Tukey's HSD, to tell which groups are the ones that actually differ. But, there is no equivalent post hoc test for Fisher's test.

The only "post hoc" thing that comes to mind is to run all pairwise comparisons for the table, and correct the p-values accordingly with, e.g., the Bonferroni method.

For a Chi square test, you could check the residuals or simply the expected-observed counts. In addition, going throught the percentages of observations in each group would probably answer your question at least partly, and this could be used with either Fisher's or Chi square test.

In R these can be done as follows:

# Percentages for rows and columns
# These a higher proportion of females than males in group D 
prop.table(tab, 1) # rows
prop.table(tab, 2) # columns

# Chi square residuals
# The largest residuals are in the group D

# Chi square expected-observed

# Chi square "post hoc" test
# For Fisher you need to do this by hand
library(NCstats) # from rforge.net
chisqPostHoc(chisq.test(t(tab))) # for A-D
chisqPostHoc(chisq.test(tab)) # for gender
  • $\begingroup$ Thanks - and how do I report it in writing? Is there a way to transform it into Pearson chi-square? $\endgroup$
    – DPY
    Sep 18, 2013 at 1:55
  • $\begingroup$ I'll give a couple of links here, see e.g., stats.stackexchange.com/questions/40542/… and yatani.jp/HCIstats/ChiSquare. Much of the specifics of reporting depends on what you are aiming at. But including the table and the test results (as shown in the documents behind the links) would be the minimum, I would say. $\endgroup$
    – anon
    Sep 18, 2013 at 16:25
  • $\begingroup$ Note that the package in the answer can be installed with source("http://www.rforge.net/NCStats/InstallNCStats.R"). Then the package is loaded with library(NCStats). $\endgroup$ Nov 10, 2017 at 14:39

As a follow-up to @JTT 's answer. The package rcompanion has a function for pairwise chi-square, fisher, or g-test of association, with options for p-value adjustment.


#   #   #

PT = pairwiseNominalIndependence(tab,
                                 compare = "column",
                                 method = "fdr")


cldList(p.adj.Fisher ~ Comparison,
        data = PT)

#   #   #

PT2 = pairwiseNominalIndependence(tab,
                                  compare = "row",
                                  method = "fdr")

cldList(p.adj.Fisher ~ Comparison,
        data = PT2)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.