示例#1
0
  /**
   * Measure of statistical dependence between two variables
   *
   * <p>http://en.wikipedia.org/wiki/Spearman's_rank_correlation_coefficient
   *
   * @param X
   * @param Y
   * @return
   */
  public double spearmanCC(List<T> X, List<T> Y) {
    LinkedList<ValueRank> valueRankX = new LinkedList<ValueRank>();
    LinkedList<ValueRank> valueRankY = new LinkedList<ValueRank>();
    Iterator itX = X.iterator();
    Iterator itY = Y.iterator();
    int size = 0;
    while (itX.hasNext() && itY.hasNext()) {
      size++;
      valueRankX.add(new ValueRank<T>((T) itX.next(), size));
      valueRankY.add(new ValueRank<T>((T) itY.next(), size));
    }

    Collections.sort(valueRankX);
    Collections.sort(valueRankY);

    itX = valueRankX.iterator();
    itY = valueRankY.iterator();

    LinkedList<Double> rankX = new LinkedList<Double>();
    LinkedList<Double> rankY = new LinkedList<Double>();
    while (itX.hasNext() && itY.hasNext()) {
      ValueRank vrx = (ValueRank) itX.next();
      ValueRank vry = (ValueRank) itY.next();
      rankX.add(vrx.getRank());
      rankY.add(vry.getRank());
    }

    Stats<Double> stat = new Stats<Double>();
    return stat.personCC(rankX, rankY);
  }
示例#2
0
 /**
  * Get the probabilities from a list of frequencies
  *
  * @param freqs
  * @return
  */
 public List<Double> probsFromFreqs(List<Integer> freqs) {
   ArrayList<Double> probs = new ArrayList<Double>();
   Stats<Integer> stat = new Stats<Integer>();
   double sum = stat.sum(freqs);
   Iterator it = freqs.iterator();
   while (it.hasNext()) {
     double p = Double.parseDouble(it.next().toString()) / sum;
     probs.add(p);
   }
   return probs;
 }