Fisher exact test in 3x2 and 4x2 contingency table in R
1
0
Entering edit mode
4.0 years ago

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 • 8.1k views
ADD COMMENT
3
Entering edit mode
4.0 years ago

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

ADD COMMENT
1
Entering edit mode

Thanks Kevin, It was really helpful. Best: Imran

ADD REPLY

Login before adding your answer.

Traffic: 1935 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6