开发者

Post-hoc pairwise fisher exact test

I used to have 2 factor by 2 level experiment that got made into a 3 facto开发者_开发问答r by 2 level experiment.

By using paste I could make 4 unique groups from my two factors and run a Fisher test with the outcome being whether an organism lived or died.

fisher.test(mortal$alv.dead,paste(mortal$Strain,mortal$capsule))

But then when I wanted to investigate pairwise comparisons between the individual groups I had to make some inelegant filtering so that only two groups entered the analysis at a time. Now that I have more groups it is too tedious to hand code each paring. So here is the Fisher test to test all the groups in one analysis

fisher.test(mortal$alv.dead,paste(mortal$Strain,mortal$capsule,mortal$cassette))

How do I set up a method that creates and tests all possible pairings?


Fairly easy using the function combn(). The only thing you should take into account, is the fact that combn will not return the names of the groups correctly when you put the fisher.test() call inside the function.

Thus we need to adjust the element in the list accordingly :

Some toy data:

mortal <- data.frame(
      alv.dead = sample(c("alv","dead"),30,replace=T),
      train = sample(letters[1:3],30,replace=T),
      capsule = sample(letters[4:5],30,replace=T),
      cassette = sample(letters[6:7],30,replace=T)
      )

Some extra variables

mortal$groups <- paste(mortal$train,mortal$capsule,mortal$cassette,sep="")
unique.groups <- unique(mortal$groups)

And the trick :

combn(unique.groups,2,function(x){
    id <- mortal$groups %in% x
    test <- fisher.test(table(mortal$alv.dead[id],mortal$groups[id]))
    test$data.name <-
      paste(
        unique(
          as.character(mortal$groups[id])
        ),collapse="-")
    return(test)}
  ,simplify=FALSE)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜