Category Archives: apache-commons-math

What is the reason behind the calculation different of apache’s DescriptiveStatistics::getPercentile method and normal percentile calculation method

Recently i have encountered the fact that org.apache.commons.math3.stat lib's DescriptiveStatistics::getPercentile method uses different approach to calculate the percentile of a given number set than the regular method. This SO answer explains the difference. here

So it seems this is not a bug but some decision they took intentionally. What is the reason behind using some different method to calculate percentile in apache.commons's lib without using standard method?.

Or is there any assumption behind this method (like assuming data set would be large) or some practical issue(like performance over accuracy)?.

Can someone explain the reason behind this algorithmic decision.

Why does tail probability in apache math drop to zero after 1E-16?

Apache Math 3.4 (and 3.3), java 1.8.0_25

import org.apache.commons.math3.distribution.ChiSquaredDistribution;
ChiSquaredDistribution chisq = new ChiSquaredDistribution(23)
System.out.println(1.0 - chisq.cumulativeProbability(130) //  1.1102230246251565E-16
System.out.println(1.0 - chisq.cumulativeProbability(131) //  0.0

Why does Apache Math return 0.0 in the second call? Most stat libraries do return values that are much smaller than 1E-16 for the tail probabilities.

ChiSquaredDistribution Javadoc

Apache Commons Math ‘ SummaryStatistics cannot be resolved to a type ‘

I am attempting to use Apache Commons Math 3.3 for a static data processing class, and am using Eclipse Mars to create it. I have successfully downloaded the bin and src files, and added them to the build path of my project; I can see them in my JRE System Library. I have also added the javadoc URL in the 'Javadoc Location' tab. I am successful in importing classes from the library.

However, when I attempt to instantiate an object from AC-M, Eclipse is unable to resolve that object as a type. For instance,

import org.apache.commons.math3.stat.descriptive.SummaryStatistics.*;

public class Stats {

public static double mean(double[] data) {
    SummaryStatistics curr = new SummaryStatistics();
    for (int a = 0; a < data.length; a++) {
    double mn = curr.getMean();
    return mn;}


The import statement works fine. However, immediately Eclipse reads an error in my 4th line of code:

'SummaryStatistics cannot be resolved to a type'

This occurs for all other objects, e.g. PearsonsCorrelation, SimpleRegression, etc. (I successfully import the respective portions of the library for all objects.) Eclipse offers an option to 'Fix project setup..', yet upon clicking, no solutions are available. I have cleaned the buildpath to no avail. I would appreciate assistance in fixing this problem.