Kruskal-Wallisの準備。順位

public static double[][] bublSortSameValsRank(double[] p){
		double[] copyP = DeepCopyDouble1(p);
		int[] ret = new int[p.length];
		double[][] ret2 = new double[p.length][5];
		for(int i=0;i<ret.length;i++){
			ret[i]=i;
		}
		boolean flag=true;
		boolean sameflag=false;
		for(int i=copyP.length-1;i>=0;i--){
			for(int j=1;j<=i;j++){
				if(copyP[j-1]==copyP[j]){
					sameflag=true;
				}
				if(copyP[j-1]>copyP[j]){
					double tmp = copyP[j-1];
					int tmpint = ret[j-1];
					copyP[j-1]=copyP[j];
					ret[j-1]=ret[j];
					copyP[j]=tmp;
					ret[j]=tmpint;
					if(flag){
						flag=false;
					}else{
						flag=true;
					}
				}
			}
		}
		
		
		
		int[] retorder = new int[ret.length];
		for(int i=0;i<ret.length;i++){
			retorder[ret[i]] = i;
		}
		
		
		int[] numsame = new int[ret.length];
		int[] sameVsameO = new int[ret.length];
		
		for(int i=0;i<retorder.length;i++){
			if(i>0){
				if(p[ret[i]]==p[ret[i-1]]){
					numsame[ret[i]]=numsame[ret[i-1]];
					sameVsameO[ret[i]]=sameVsameO[ret[i-1]];
				}else{
					
					numsame[ret[i]]=1;
					sameVsameO[ret[i]]=retorder[ret[i]];
					for(int j=i+1;j<ret.length;j++){
						if(p[ret[j]]==p[ret[j-1]]){
	
							numsame[ret[i]]++;
						}else{
							break;
						}
					}
				}
			}else{
	
				numsame[ret[i]]=1;
				sameVsameO[ret[i]]=retorder[ret[i]];
				for(int j=i+1;j<ret.length;j++){
					if(p[ret[j]]==p[ret[j-1]]){
	
						numsame[ret[i]]++;
					}else{
						break;
					}
				}
				
			}
		}
		
		
		
		
		int[] revorder = new int[ret.length];
		for(int i=0;i<ret.length;i++){
			revorder[i] = ret.length-(sameVsameO[i]+numsame[i]);
		}
		
		System.out.println("Input ");
		for(int i=0;i<p.length;i++){
			System.out.println("i=" + i  + "  "+ p[i]);
			
		}
		System.out.println("Ascending-ordered list ");
		for(int i=0;i<ret.length;i++){
			System.out.println("i=" + i + "  " + ret[i] + " " + p[ret[i]]);
		}
		System.out.println("(1) ascending order.  Different number for multiple values ");
		for(int i=0;i<retorder.length;i++){
			System.out.println("i=" + i + "  "+ retorder[i]);
			ret2[i][0]=retorder[i];
		}
		System.out.println("(2) ascending order.  Same number for multiple values ");
		for(int i=0;i<sameVsameO.length;i++){
			System.out.println("i=" + i + "  "+ sameVsameO[i]);
			ret2[i][1]=sameVsameO[i];
		}
		System.out.println("(3) descending order. Same number for multiple values");
		for(int i=0;i<revorder.length;i++){
			System.out.println("i=" + i + "  "+ revorder[i]);
			ret2[i][2]=revorder[i];
		}
		System.out.println("(4) number of records of the same value with self.");
		for(int i=0;i<numsame.length;i++){
			System.out.println("i=" + i + "  "+ numsame[i]);
			ret2[i][3]=numsame[i];
		}
		System.out.println("(5) Rank.");
		for(int i=0;i<numsame.length;i++){
			ret2[i][4]=ret2[i][2]+(double)(p.length+1-ret2[i][1]-ret2[i][2])/2;
			System.out.println("i=" + i + "  "+ ret2[i][4]);
			//ret2[i][4]=numsame[i];
		}
		//ret[i]=(double)sortOrder[i][2]+(double)(d.length+1-sortOrder[i][1]-sortOrder[i][2])/2;
		//int[][] ret2 = new int[0][0];
		return ret2;
	}