Re: Mathematicians !! Percentile/Quartile function
- Posted by Pete Stoner <stoner.pete at gmail.com> Sep 07, 2005
- 648 views
Juergen Luethje wrote: > > Pete Stoner wrote: > > > I need some mathematical help, I want a function that calculates the > > 1st, 2nd and 3rd Quartiles (otherwise known as 25th, 50th and 75th > > percentiles) from a sequence of values. I can get the 2nd quartile as > > that is also the median and I can get the 1st and 3rd quartiles to > > agree with Excel and 123 if the qty of values is odd, but when I have > > an even quantity the 1st and 3rd quartiles are wrong. > > i.e. for values of {2, 6, 7, 10, 14, 15, 16} the quartiles are 6.5, 10 > > and 14.5 > > IMHO it must be 6, 10, 15. Thanks for the reply Juergen, I understand why you say that, I've read that there are different ways to calculate this but both Lotus 123 and Excel seem to include the median value when calculating the 1st and 3rd quartiles which gives 6.5, 10, 14.4 > > > but for a range of {2, 6, 7, 10, 14, 15} the correct quartiles seem to > > be 6.25, 8.5 & 13 > > <snip> > > It depends whether we have qualitative or quantitative data. > If you don't know what that means, see e.g. here for an explanation: > <a > href="http://davidmlane.com/hyperstat/intro.html">http://davidmlane.com/hyperstat/intro.html</a> I don't know which type 123 and Excel use (neither say which in the help) but I would like my calculation to match the output of those as they both give the same results... > > >From what you wrote it looks as if you have quantitative data. > Then after my algorithm the wanted quantiles are 6, 8.5, 14. > > Following you'll find some code for calculating an arbitrary number of > arbitrary quantiles (e.g. the 25th percentile is the 0.25 quantile). > Because calculating the mean is only allowed for quantitative data, you > must pass TRUE or FALSE to the function as second parameter, depending > on whether or not your data are quantitative. > > The algorithm is according to the information given in a German > statistical textbook. AFAIK there are other ways to calculate quantiles, > which might return different results in some cases. > > <snip> Your routine is more adaptable than mine and the results for the even quantity are the same for both (but do not match 123 and Excel), but mine matches the spreadsheets for an odd qty whereas yours is different again. I'm curious as to how they are calculating it.. It would seem to be the 'accepted' norm since 2 products from different companies give the same results.. Regards Pete.