1

I was doing some social science research and stumbled upon an article discussing the different exact tests, including Bernard's test. Several authors have discussed the differences between Fisher's Exact test and Bernard's test (Lydersen in 2009, and Mehta and Senchaudhuri in 2003), but I was just curious if I could see the difference for myself (and learn a little more about R in the process). I found a way to get Fisher's Test to work, but Barnard's Test has eluded me:

 library(plyr)
 library(Barnard)

 rook <- expand.grid(a=0:5,b=0:5,c=0:5,d=0:5)

 sums <- ddply(rook, .(a,b,c,d), sum)

 system.time(
 Fisher.l <- ddply(rook, .(a,b,c,d),function(z)
      fisher.test(matrix(unlist(z[,c(1,2,3,4)]),
      ncol=2),alternative="less")$p.value)
 )

Neither of these work though... they were two ways of trying to do the same thing...

 system.time(
      Barnard <- ddply(rook, .(a,b,c,d), function(z)
      barnardw.test(unlist(z[,c(1,2,3,4)]), ncol=2))$p.value[[1]])
 )

 system.time(
      Barnard <- ddply(rook, .(a,b,c,d), function(z)
      barnardw.test(z[,1],z[,2],z[,3],z[,4]))$p.value[[1]])
 )
  • I found R code for Barnard's exact test here, downloaded it and it ran. I do not know whether it might be of interest or helpful. https://raw.github.com/talgalili/R-code-snippets/master/Barnard.R – Mark Miller Apr 25 '12 at 02:49
  • Your second example works for me, when I remove the lonely )s. – Dieter Menne Apr 25 '12 at 09:17

0 Answers0