Is there any java api for calculating interquartile range? I was wondering apache commons math library contains all the stats function like mean, median, mode but i could not find any thing for IQR.
The two most common methods for calculating interquartile range are the exclusive and inclusive methods. The exclusive method excludes the median when identifying Q1 and Q3, while the inclusive method includes the median as a value in the data set in identifying the quartiles.
To find the interquartile range (IQR), first find the median (middle value) of the lower and upper half of the data. These values are quartile 1 (Q1) and quartile 3 (Q3). The IQR is the difference between Q3 and Q1.
Outliers are values below Q1-1.5(Q3-Q1) or above Q3+1.5(Q3-Q1) or equivalently, values below Q1-1.5 IQR or above Q3+1.5 IQR. These are referred to as Tukey fences. For the diastolic blood pressures, the lower limit is 64 - 1.5(77-64) = 44.5 and the upper limit is 77 + 1.5(77-64) = 96.5.
I'm not sure, but maybe you can use getPercentile from DescriptiveStatistics class of Apache Commons Math, like in the following code sample.
double[] data = // obtain data here
DescriptiveStatistics da = new DescriptiveStatistics(data);
double iqr = da.getPercentile(75) - da.getPercentile(25);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With