Fisher’s Exact Test using R

 

Say we want to test the independence between cyl and drv using mpg data file.

> table(cyl, drv)
   drv
cyl  4  f  r
  4 23 58  0
  5  0  4  0
  6 32 43  4
  8 48  1 21

> fisher.test(table(cyl, drv), workspace = 1000000)

 Fisher's Exact Test for Count Data

data: table(cyl, drv)
p-value < 2.2e-16
alternative hypothesis: two.sided

Note you need to set a big number for the workspace = option in order to make the algorithm converge for calculating non-simulated p-values larger than 2 by 2 tables.

 

 

See Also:

Do the same test in SAS

Leave a Reply

Your email address will not be published. Required fields are marked *