r - Post-hoc pairwise fisher exact test -


i used have 2 factor 2 level experiment got made 3 factor 2 level experiment.

by using paste make 4 unique groups 2 factors , run fisher test outcome being whether organism lived or died.

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

but when wanted investigate pairwise comparisions between individual groups had make inelegant filtering 2 groups entered analysis @ time. have more groups tedious hand code each paring. here fisher test test groups in 1 analysis

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

how set method creates , tests possible pairings?

fairly easy using function combn(). thing should take account, fact combn not return names of groups correctly when put fisher.test() call inside function.

thus need adjust element in 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 variables

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

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

Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -