TXT

JT.test

By Carmen Reynolds,2014-04-23 23:41
11 views 0
JT.test

    JT.test=function(x){ #### x形式不变 y<-x[,2]

    m=max(y)

    n=0

    for(i in 1:m){

    l=sum(x[,2]==i)

    if(l>n-1){

    n<-l

    }else{

    n=n

    }

    }

    N=m*n

    a=array(n,m)

    jz=matrix(NA, nrow = n, ncol = m)

    for(i in 1:m){

    l=sum(x[,2]==i)

    if(l

    jz[1:l,i]<-c(x[,1][which(x[,2]==i)])

    }else{jz[,i]<-c(x[,1][which(x[,2]==i)])

    }

    }

    M=array(NA,m)

    b=array(NA,m)

    nt=0

    for(i in 1:m){

    M[i]<-median(jz[,i],na.rm=TRUE)

    b[i]<-i

    }

    xl=matrix(NA, nrow = n, ncol = 1)

    for(i in 1:(m-1)){

     for(j in (i+1):m){

     if(M[i]>M[j]){

     nt<-b[i]

     b[i]<-b[j]

     b[j]<-nt

     xl<-jz[,i]

     jz[,i]<-jz[,j]

     jz[,j]<-xl

     }

    }

    }

    ybs=array(n,m)

    for(j in 1:m){

     for(i in 1:n){

     if(is.na(jz[i,j]==TRUE)){

     ybs[j]=ybs[j]-1

     }

    }

    }

    N=sum(ybs)

    ds=choose(m,2)

    U <- matrix(0,ds,ds) for(i in 1:(m-1)){

     for(j in (i+1):m){

     x1=na.omit(jz[,i])

     x2=na.omit(jz[,j])

     U[i,j]<- sum(outer(x1,x2,"-")<0)+sum(outer(x1,x2,"-")==0)/2

     }

    }

    J2=sum(U)

    hehe=0

    for(i in 1:m){

    hehe=hehe+ybs[i]^2 }

    haha=0

    for(i in 1:m){

    haha=haha+ybs[i]^2*(2*ybs[i]+3)

    }

    z <- (J2-(N^2-hehe)/4)/sqrt((N^2*(2*N+3)-haha)/72)

    p.value <- 1-pnorm(z) list(b,p.value)

    }

Report this document

For any questions or suggestions please email
cust-service@docsford.com