예제 #1
0
  public void compairWise(
      ArrayList<Double> aList, ArrayList<Double> bList, String aGroup, String bGroup) {
    // a should be the small
    // b should be the larger

    ArrayList<Integer> randomNumberList = new ArrayList<Integer>();
    double a[] = new double[aList.size()];
    double b[] = new double[aList.size()];

    for (int i = 0; i < aList.size(); ) {
      a[i] = aList.get(i);
      while (true) {
        int randomIndex = r.nextInt(bList.size());
        if (!randomNumberList.contains(randomIndex)) {
          randomNumberList.add(randomIndex);
          b[i] = bList.get(randomIndex);
          break;
        }
      }
      i++;
    }

    randomNumberList.clear();

    /*for(int i = 0; i<aList.size();){

    	System.out.println("a"+a[i]+"b"+b[i]);

    }*/

    int df = aList.size() + aList.size() - 2;
    TTest ttest = new TTest();
    System.out.println("-----------------------------");
    System.out.println(bGroup + " Vs " + aGroup);

    System.out.println(aGroup + " Mean:" + getMean(a));
    System.out.println(aGroup + " Standard Deviation:" + getStdDev(a));
    System.out.println(bGroup + " Mean:" + getMean(b));
    System.out.println(bGroup + " Standard Deviation:" + getStdDev(b));

    System.out.println("t_statistic:" + ttest.t(a, b));
    System.out.println("p value:" + ttest.tTest(a, b));
    System.out.println("DF:" + df);
    double corr = new PearsonsCorrelation().correlation(a, b);
    System.out.println("Correlation: " + corr);
    System.out.println("\n\n");
  }
예제 #2
0
  public void compare() {

    compairWise(toplevelList.get("Asian"), toplevelList.get("White"), "Asian", "White");
    compairWise(
        toplevelList.get("AfricanAmerican"), toplevelList.get("White"), "AfricanAmerican", "White");
    compairWise(toplevelList.get("Hispanic"), toplevelList.get("White"), "Hispanic", "White");

    compairWise(list.get("AsianM"), list.get("WhiteM"), "Asian Male", "White Male");
    compairWise(list.get("AsianF"), list.get("WhiteF"), "Asian Female", "White Female");

    compairWise(
        list.get("AfricanAmericanM"), list.get("WhiteM"), "AfricanAmerican Male", "White Male");
    compairWise(
        list.get("AfricanAmericanF"), list.get("WhiteF"), "AfricanAmerican Female", "White Female");

    compairWise(list.get("HispanicM"), list.get("WhiteM"), "Hispanic Male", "White Male");
    compairWise(list.get("HispanicF"), list.get("WhiteF"), "Hispanic Female", "White Female");

    white = new double[nonWhiteSize];
    nonWhite = new double[nonWhiteSize];
    ArrayList<Integer> randomNumberList = new ArrayList<Integer>();

    for (int i = 0; i < nonWhiteSize; ) {

      while (true) {
        int randomIndex = r.nextInt(whiteSize);
        if (!randomNumberList.contains(randomIndex)) {
          randomNumberList.add(randomIndex);
          white[i] = toplevelList.get("White").get(randomIndex);
          break;
        }
      }
      i++;
    }

    /*for(int i = 0; i<nonWhiteSize;){
    	System.out.println("Random Number:"+randomNumberList.get(i)+", white["+i+"]: "+ white[i]);
    	i++;
    }*/

    for (int i = 0; i < toplevelList.get("AfricanAmerican").size(); i++) {
      nonWhite[i] = toplevelList.get("AfricanAmerican").get(i);
    }

    int j = 0;
    for (int i = toplevelList.get("AfricanAmerican").size();
        i < toplevelList.get("AfricanAmerican").size() + toplevelList.get("Asian").size();
        i++) {
      nonWhite[i] = toplevelList.get("Asian").get(j);
      j++;
    }

    j = 0;
    for (int i = toplevelList.get("AfricanAmerican").size() + toplevelList.get("Asian").size();
        i < nonWhiteSize;
        i++) {
      nonWhite[i] = toplevelList.get("Hispanic").get(j);
      j++;
    }

    int df = (int) (nonWhiteSize + nonWhiteSize - 2);
    TTest ttest = new TTest();
    System.out.println("-----------------------------");
    System.out.println("White Vs Non-White");

    System.out.println("White Mean:" + getMean(white));
    System.out.println("White Standard Deviation:" + getStdDev(white));
    System.out.println("Non-White Mean:" + getMean(nonWhite));
    System.out.println("Non-White Standard Deviation:" + getStdDev(nonWhite));

    System.out.println("t_statistic:" + ttest.t(white, nonWhite));
    System.out.println("p value:" + ttest.tTest(white, nonWhite));
    System.out.println("DF:" + df);
    double corr = new PearsonsCorrelation().correlation(white, nonWhite);
    System.out.println("Correlation: " + corr);
  }