This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Fisher exact test in 3x2 and 4x2 contingency table in R

Hi Everyone, Are there any R scripts to perform Fisher exact test in 3x2 and 4x2 contingency table in R. I would appreciate if anyone can share their experience to perform such stats. Thank you! Imran

r

1 answer

Hi,

You just need the fisher.test() function:

3x2 contingency table

df <- data.frame(
  group1 = c(45,55),
  group2 = c(20,80),
  group3 = c(50,50),
  row.names = c('Control','Treatment'))
df
          group1 group2 group3
Control       45     20     50
Treatment     55     80     50

fisher.test(df)

        Fisher's Exact Test for Count Data

data:  df
p-value = 0.0000103
alternative hypothesis: two.sided

4x2 contingency table

df <- data.frame(
  group1 = c(45,55),
  group2 = c(35,65),
  group3 = c(50,50),
  group4 = c(52,48),
  row.names = c('Control','Treatment'))

df
          group1 group2 group3 group4
Control       45     35     50     52
Treatment     55     65     50     48

fisher.test(df)

        Fisher's Exact Test for Count Data

data:  df
p-value = 0.07024
alternative hypothesis: two.sided

--------

Be sure to check all possible parameters by typing ?fisher.test and then hitting ENTER (q to then exit back to the main terminal).

Kevin

Log in to answer this question.