@Test public void testPercentiles() { logger.info("percentiles"); FlatDataCollection flatDataCollection = generateFlatDataCollection(); int cutPoints = 4; AssociativeArray expResult = new AssociativeArray(); expResult.put(25.0, -12.5725); expResult.put(50.0, 2.565); expResult.put(75.0, 26.6925); AssociativeArray result = Descriptives.percentiles(flatDataCollection, cutPoints); for (Object key : result.keySet()) { double rounded = PHPMethods.round(result.getDouble(key), 5); result.put(key, rounded); } assertEquals(expResult, result); }
public static AssociativeArray percentiles(FlatDataCollection flatDataCollection, int cutPoints) { double[] doubleArray = flatDataCollection.stream().filter(x -> x!=null).mapToDouble(TypeInference::toDouble).toArray(); int n = doubleArray.length; if(n<=0 || cutPoints<=0 || n<cutPoints) { throw new IllegalArgumentException("All the parameters must be positive and n larger than cutPoints."); } Arrays.sort(doubleArray); AssociativeArray percintiles = new AssociativeArray(); double counter = 1.0; while(true) { double perc = counter/cutPoints; Double tc2=(n+1.0)*perc; int CCk2=tc2.intValue(); int CCk2_plus1=CCk2+1; int Ck2=CCk2-1; int Ck2_plus1=CCk2_plus1-1; double g2Star=tc2-CCk2; if(Ck2<doubleArray.length) { Double key=100*perc; Double Ck2Value = doubleArray[Ck2]; if(Ck2_plus1<doubleArray.length) { Double Ck2_plus1Value = doubleArray[Ck2_plus1]; percintiles.put(key, (1-g2Star)*Ck2Value+g2Star*Ck2_plus1Value); } else { percintiles.put(key, Ck2Value); break; } } else { break; } ++counter; } return percintiles; }
Descriptives { public static AssociativeArray percentiles(FlatDataCollection flatDataCollection, int cutPoints) { double[] doubleArray = flatDataCollection.stream().filter(x -> x!=null).mapToDouble(TypeInference::toDouble).toArray(); int n = doubleArray.length; if(n<=0 || cutPoints<=0 || n<cutPoints) { throw new IllegalArgumentException("All the parameters must be positive and n larger than cutPoints."); } Arrays.sort(doubleArray); AssociativeArray percintiles = new AssociativeArray(); double counter = 1.0; while(true) { double perc = counter/cutPoints; Double tc2=(n+1.0)*perc; int CCk2=tc2.intValue(); int CCk2_plus1=CCk2+1; int Ck2=CCk2-1; int Ck2_plus1=CCk2_plus1-1; double g2Star=tc2-CCk2; if(Ck2<doubleArray.length) { Double key=100*perc; Double Ck2Value = doubleArray[Ck2]; if(Ck2_plus1<doubleArray.length) { Double Ck2_plus1Value = doubleArray[Ck2_plus1]; percintiles.put(key, (1-g2Star)*Ck2Value+g2Star*Ck2_plus1Value); } else { percintiles.put(key, Ck2Value); break; } } else { break; } ++counter; } return percintiles; } }
Descriptives { public static AssociativeArray percentiles(FlatDataCollection flatDataCollection, int cutPoints) { double[] doubleArray = flatDataCollection.stream().filter(x -> x!=null).mapToDouble(TypeInference::toDouble).toArray(); int n = doubleArray.length; if(n<=0 || cutPoints<=0 || n<cutPoints) { throw new IllegalArgumentException("All the parameters must be positive and n larger than cutPoints."); } Arrays.sort(doubleArray); AssociativeArray percintiles = new AssociativeArray(); double counter = 1.0; while(true) { double perc = counter/cutPoints; Double tc2=(n+1.0)*perc; int CCk2=tc2.intValue(); int CCk2_plus1=CCk2+1; int Ck2=CCk2-1; int Ck2_plus1=CCk2_plus1-1; double g2Star=tc2-CCk2; if(Ck2<doubleArray.length) { Double key=100*perc; Double Ck2Value = doubleArray[Ck2]; if(Ck2_plus1<doubleArray.length) { Double Ck2_plus1Value = doubleArray[Ck2_plus1]; percintiles.put(key, (1-g2Star)*Ck2Value+g2Star*Ck2_plus1Value); } else { percintiles.put(key, Ck2Value); break; } } else { break; } ++counter; } return percintiles; }  }
Descriptives { public static AssociativeArray percentiles(FlatDataCollection flatDataCollection, int cutPoints) { double[] doubleArray = flatDataCollection.stream().filter(x -> x!=null).mapToDouble(TypeInference::toDouble).toArray(); int n = doubleArray.length; if(n<=0 || cutPoints<=0 || n<cutPoints) { throw new IllegalArgumentException("All the parameters must be positive and n larger than cutPoints."); } Arrays.sort(doubleArray); AssociativeArray percintiles = new AssociativeArray(); double counter = 1.0; while(true) { double perc = counter/cutPoints; Double tc2=(n+1.0)*perc; int CCk2=tc2.intValue(); int CCk2_plus1=CCk2+1; int Ck2=CCk2-1; int Ck2_plus1=CCk2_plus1-1; double g2Star=tc2-CCk2; if(Ck2<doubleArray.length) { Double key=100*perc; Double Ck2Value = doubleArray[Ck2]; if(Ck2_plus1<doubleArray.length) { Double Ck2_plus1Value = doubleArray[Ck2_plus1]; percintiles.put(key, (1-g2Star)*Ck2Value+g2Star*Ck2_plus1Value); } else { percintiles.put(key, Ck2Value); break; } } else { break; } ++counter; } return percintiles; }  static int count(Iterable it); static double sum(FlatDataCollection flatDataCollection); static double mean(FlatDataCollection flatDataCollection); static double meanSE(FlatDataCollection flatDataCollection); static double median(FlatDataCollection flatDataCollection); static double min(FlatDataCollection flatDataCollection); static double max(FlatDataCollection flatDataCollection); static double minAbsolute(FlatDataCollection flatDataCollection); static double maxAbsolute(FlatDataCollection flatDataCollection); static double range(FlatDataCollection flatDataCollection); static double geometricMean(FlatDataCollection flatDataCollection); static double harmonicMean(FlatDataCollection flatDataCollection); static double variance(FlatDataCollection flatDataCollection, boolean isSample); static double std(FlatDataCollection flatDataCollection, boolean isSample); static double cv(double std, double mean); static double moment(FlatDataCollection flatDataCollection, int r); static double moment(FlatDataCollection flatDataCollection, int r, double mean); static double kurtosis(FlatDataCollection flatDataCollection); static double kurtosisSE(FlatDataCollection flatDataCollection); static double skewness(FlatDataCollection flatDataCollection); static double skewnessSE(FlatDataCollection flatDataCollection); static AssociativeArray percentiles(FlatDataCollection flatDataCollection, int cutPoints); static AssociativeArray quartiles(FlatDataCollection flatDataCollection); static double covariance(TransposeDataList transposeDataList, boolean isSample); static double autocorrelation(FlatDataList flatDataList, int lags); static AssociativeArray frequencies(FlatDataCollection flatDataCollection); static FlatDataCollection mode(FlatDataCollection flatDataCollection); static void normalize(AssociativeArray associativeArray); static void normalizeExp(AssociativeArray associativeArray); }
Descriptives { public static AssociativeArray percentiles(FlatDataCollection flatDataCollection, int cutPoints) { double[] doubleArray = flatDataCollection.stream().filter(x -> x!=null).mapToDouble(TypeInference::toDouble).toArray(); int n = doubleArray.length; if(n<=0 || cutPoints<=0 || n<cutPoints) { throw new IllegalArgumentException("All the parameters must be positive and n larger than cutPoints."); } Arrays.sort(doubleArray); AssociativeArray percintiles = new AssociativeArray(); double counter = 1.0; while(true) { double perc = counter/cutPoints; Double tc2=(n+1.0)*perc; int CCk2=tc2.intValue(); int CCk2_plus1=CCk2+1; int Ck2=CCk2-1; int Ck2_plus1=CCk2_plus1-1; double g2Star=tc2-CCk2; if(Ck2<doubleArray.length) { Double key=100*perc; Double Ck2Value = doubleArray[Ck2]; if(Ck2_plus1<doubleArray.length) { Double Ck2_plus1Value = doubleArray[Ck2_plus1]; percintiles.put(key, (1-g2Star)*Ck2Value+g2Star*Ck2_plus1Value); } else { percintiles.put(key, Ck2Value); break; } } else { break; } ++counter; } return percintiles; }  static int count(Iterable it); static double sum(FlatDataCollection flatDataCollection); static double mean(FlatDataCollection flatDataCollection); static double meanSE(FlatDataCollection flatDataCollection); static double median(FlatDataCollection flatDataCollection); static double min(FlatDataCollection flatDataCollection); static double max(FlatDataCollection flatDataCollection); static double minAbsolute(FlatDataCollection flatDataCollection); static double maxAbsolute(FlatDataCollection flatDataCollection); static double range(FlatDataCollection flatDataCollection); static double geometricMean(FlatDataCollection flatDataCollection); static double harmonicMean(FlatDataCollection flatDataCollection); static double variance(FlatDataCollection flatDataCollection, boolean isSample); static double std(FlatDataCollection flatDataCollection, boolean isSample); static double cv(double std, double mean); static double moment(FlatDataCollection flatDataCollection, int r); static double moment(FlatDataCollection flatDataCollection, int r, double mean); static double kurtosis(FlatDataCollection flatDataCollection); static double kurtosisSE(FlatDataCollection flatDataCollection); static double skewness(FlatDataCollection flatDataCollection); static double skewnessSE(FlatDataCollection flatDataCollection); static AssociativeArray percentiles(FlatDataCollection flatDataCollection, int cutPoints); static AssociativeArray quartiles(FlatDataCollection flatDataCollection); static double covariance(TransposeDataList transposeDataList, boolean isSample); static double autocorrelation(FlatDataList flatDataList, int lags); static AssociativeArray frequencies(FlatDataCollection flatDataCollection); static FlatDataCollection mode(FlatDataCollection flatDataCollection); static void normalize(AssociativeArray associativeArray); static void normalizeExp(AssociativeArray associativeArray);  }