Created
March 26, 2017 03:52
-
-
Save sithjaisong/6d59811b5073bea95bba24753f149300 to your computer and use it in GitHub Desktop.
Perform pairwise Wilcoxon test, classify groups by significance and plot results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ref:https://fabiomarroni.wordpress.com/2017/03/25/perform-pairwise-wilcoxon-test-classify-groups-by-significance-and-plot-results/ | |
library(multcompView) | |
first.set<-cbind(rnorm(100,mean=1.8),1) | |
second.set<-cbind(rnorm(100,mean=0.9),2) | |
third.set<-cbind(rnorm(100,mean=1),3) | |
full<-rbind(first.set,second.set,third.set) | |
pp<-pairwise.wilcox.test(full[,1], full[,2], p.adjust.method = "none", paired = FALSE) | |
mymat<-tri.to.squ(pp$p.value) | |
myletters<-multcompLetters(mymat,compare="<=",threshold=0.05,Letters=letters) | |
boxplot(full[,1] ~ full[,2],ylab="Something nice",names=c("Set 1","Set 2","Set 3"),ylim=c(min(full[,1]),0.2+max(full[,1]))) | |
text(c(1,2,3),0.1+max(full[,1]),c(myletters$Letters[1],myletters$Letters[2],myletters$Letters[3])) | |
tri.to.squ<-function(x) | |
{ | |
rn<-row.names(x) | |
cn<-colnames(x) | |
an<-unique(c(cn,rn)) | |
myval<-x[!is.na(x)] | |
mymat<-matrix(1,nrow=length(an),ncol=length(an),dimnames=list(an,an)) | |
for(ext in 1:length(cn)) | |
{ | |
for(int in 1:length(rn)) | |
{ | |
if(is.na(x[row.names(x)==rn[int],colnames(x)==cn[ext]])) next | |
mymat[row.names(mymat)==rn[int],colnames(mymat)==cn[ext]]<-x[row.names(x)==rn[int],colnames(x)==cn[ext]] | |
mymat[row.names(mymat)==cn[ext],colnames(mymat)==rn[int]]<-x[row.names(x)==rn[int],colnames(x)==cn[ext]] | |
} | |
} | |
return(mymat) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment