########################################################################## #########2-sample Rank-Sum Test for clustered data ####################### ########################################################################## ###Note: this function only works for 2 sample test ###Note: the input is Cluster, X(the value), and grp(the Group) ### Data must be arranged in the way illustrated in the sample below ### the output of the function is S, E(S), Var(S), and z-statistic ### Written by: Xu, Ping ### Distributed "as is" without warrantee of any kind; use at your own risk! ########################################################################## clus.rank.sum<-function(Cluster,X,grp) { #####calculate quantity 2 (using the pooled estimate of F) n<-length(X) F.hat<-numeric(n) for (i in 1:n){ F.hat[i]<-(sum(X<=X[i])+sum(X clus.rank.sum(Cluster,X,grp) $S [1] 0.921875 $E.S [1] 0.8333333 $Var.S [1] 0.0056293 $z.stat [1] 1.180105 $p.value [1] 0.2379586