Java List Sort interpolateLinearlyQuantile(List sortedDataAscendingOrder, Double p)

Here you can find the source of interpolateLinearlyQuantile(List sortedDataAscendingOrder, Double p)

Description

Interpolate linearly an quantile Inspired on: http://msenux.redwoods.edu/math/R/boxplot.php

License

LGPL

Parameter

Parameter Description
sortedDataAscendingOrder sorted data in ascending order (NOT NULL)
p percentage

Return

Double interpolated linearly quantile

Declaration

private final static Double interpolateLinearlyQuantile(List<Double> sortedDataAscendingOrder, Double p) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.util.List;

public class Main {
    /**/*  w  w  w  .  jav a2s . co  m*/
     * Interpolate linearly an quantile
     * 
     * Inspired on: http://msenux.redwoods.edu/math/R/boxplot.php
     * 
     * @param sortedDataAscendingOrder sorted data in ascending order (NOT NULL) 
     * @param p percentage
     * @return Double interpolated linearly quantile
     */
    private final static Double interpolateLinearlyQuantile(List<Double> sortedDataAscendingOrder, Double p) {
        int n = sortedDataAscendingOrder.size();
        double position = (1 + (p * (n - 1)));

        int leftIndex = (int) Math.floor(position) - 1;
        int rightIndex = (int) Math.ceil(position) - 1;
        Double quantile;

        if (leftIndex == rightIndex) {
            quantile = sortedDataAscendingOrder.get(leftIndex);
        } else {
            Double leftIndexValue = sortedDataAscendingOrder.get(leftIndex);
            Double rightIndexValue = sortedDataAscendingOrder.get(rightIndex);

            quantile = leftIndexValue + 0.5 * (rightIndexValue - leftIndexValue);
        }

        return quantile;
    }
}

Related

  1. getSortedKetList(HashMap numKnownGenesHashMap)
  2. getSortedList(Collection collection)
  3. getSortedList(Set items)
  4. getSortedStringList(List pathList)
  5. getZipfPlotData(List sortedCount)
  6. isEqualList(final List list1, final List list2, Comparator c, boolean sortList)
  7. isSorted(Iterable list)
  8. isSorted(List list)
  9. isSorted(List list)