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]])
)