Java – use Apache commons math to determine confidence intervals
I have a set of benchmark data. I use Apache math commons to calculate summary statistics Now I want to use the package to calculate, for example, the confidence interval of the arithmetic mean of the data Run time measurement
Is this possible? I believe the package supports this, but I failed from where I started
This is the solution I finally used as suggested by Brent Worden:
private double getConfidenceIntervalWidth(StatisticalSummary statistics,double significance) { TDistribution tDist = new TDistribution(statistics.getN() - 1); double a = tDist.inverseCumulativeProbability(1.0 - significance / 2); return a * statistics.getStandardDeviation() / Math.sqrt(statistics.getN()); }
Solution
Apache commons math does not directly support building confidence intervals However, it does have everything to calculate them
First, use summarystatistics or some other statisticalsummary implementation to summarize your data into sample statistics
Next, use tDISTRIBUTION to calculate the critical value of the required confidence Degrees of freedom can be inferred from summary statistics n
Finally, calculate your lower and upper confidence limits using the mean, variance and N attribute values in the summary statistics and the t-critical value from the distribution