# Wilcoxon rank sum test # Example: Hollander & Wolfe (1973) # Permeability constants of the human chorioamnion (a placental membrane) at term (x) and between 12 to 26 weeks gestational age (y). The alternative of interest is greater permeability of the human chorioamnion for the term pregnancy. x <- c(0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46) y <- c(1.15, 0.88, 0.90, 0.74, 1.21) z<-sort(c(x,y)) T<-sum(which(z %in% x))-10*11/2 T ranksum<-function(n,m,T){ T=T+m*(m+1)/2 x<-c(1:n) l<-choose(n,m) k<-rep(0,l) y<-combn(x,m) for(j in 1:l){ k[j]<-sum(x[y[,j]])} pval<-length(which(k>=T))/choose(n,m) return(pval) } ranksum(15,10,35) wilcox.test( c(0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46), c(1.15, 0.88, 0.90, 0.74, 1.21),alternative="greater") # Permutation test using t-statistic T<-t.test(x,y)$statistic t.pval<-function(a,b,T){ c<-cbind(a,b) m<-length(b) n<-length(c) x<-c(1:n) l<-choose(n,m) t<-rep(0,l) y<-combn(x,m) for(j in 1:l){ t[j]<-t.test(c[y[,j]],c[-y[,j]])$statistic} pval<-2*length(which(t>=T))/l pval<-ifelse(pval>1, 2-pval, pval) return(pval) } t.pval(x,y,T)