Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vv111y/aa6a67fb080814687a3acfe327fca614 to your computer and use it in GitHub Desktop.
Save vv111y/aa6a67fb080814687a3acfe327fca614 to your computer and use it in GitHub Desktop.
Friedman test with post-hoc using Bergmann-Hommel procedure
friedman.test.with.post.hoc <- function(data, alpha = 0.05)
{
print("Check if you missing the packages 'graph' and 'Rgraphviz'. Try to install them using bioconductor")
#source("http://bioconductor.org/biocLite.R")
#biocLite(c("graph","Rgraphviz"))
# Loading needed packages
if(!require(ggplot2))
{
print("You are missing the package 'ggplot2', we will now try to install it...")
install.packages("ggplot2")
library(ggplot2)
}
if(!require(scmamp))
{
print("You are missing the package 'scmamp', we will now try to install it...")
install.packages("scmamp")
library(scmamp)
}
pre.results <- friedmanTest(data)
imanDavenport.result <- imanDavenportTest(data)
if(pre.results$p.value < alpha){
post.results <- NULL
if(length(colnames(my_data)) > 9){
post.results <- postHocTest(data=data, test="friedman", correct="shaffer")
}else{
post.results <- postHocTest(data=data, test="friedman", correct="bergmann")
}
## LaTeX formated: Significances highlighted in bold
#avg.val <- post.results$summary
#best.res <- avg.val == max(avg.val)
#stat.diff <- post.results$corrected.pval < 0.05
#stat.diff[is.na(stat.diff)] <- FALSE
#writeTabular(table = avg.val, format = 'f', bold = best.res, mark = stat.diff, digits = 1)
bold <- post.results$corrected.pval < alpha
bold[is.na(bold)] <- FALSE
writeTabular(table=post.results$corrected.pval, format='f', bold=bold, hrule=0, vrule=0)
friedman.mc <- friedmanmc(data.matrix(data))
plt <- plotPvalues(post.results$corrected.pval, alg.order=order(post.results$summary)) + labs(title=paste("Corrected p-values using Bergmann and Hommel procedure",sep="")) + xlab("Algorithm") + ylab("Algotithm") + scale_fill_gradientn("Corrected p-values" , colours = c("grey15" , "grey30"))
list.to.return <- list(Friedman = pre.results, ImanDavenport = imanDavenport.result, PostHoc = post.results, FriedmanMC = friedman.mc, Plt = plt)
return(list.to.return)
}
else{
print("The results where not significant. There is no need for a post-hoc test.")
list.to.return <- list(Friedman = pre.results, ImanDavenport = imanDavenport.result, PostHoc = NULL, FriedmanMC = NULL, Plt = NULL)
return(list.to.return)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment