Re: Mathematicians !! Percentile/Quartile function
- Posted by CChris <christian.cuvier at insee.fr> Sep 08, 2005
- 616 views
Pete Stoner wrote: > > Pete Stoner wrote: > > > > Pete Lomax wrote: > > > > > > On Wed, 07 Sep 2005 09:45:41 -0700, Pete Stoner > > > <guest at RapidEuphoria.com> wrote: > > > > > > >i.e. for values of {2, 6, 7, 10, 14, 15, 16} the quartiles are 6.5, 10 > > > >and 14.5 > > > >but for a range of {2, 6, 7, 10, 14, 15} the correct quartiles seem to be > > > >6.25, 8.5 & 13 > > > FWIW, (and strictly from observation only!) the first is (or might be) > > > (6+7)/2, 10, (14+15)/2, while ths second is (or might be) > > > (2+6+7+10)/2, (7+10)/2, (10+14+15)/2 > > > > > > As I don't have either Excel or 123 to hand, I can't experiment more, > > > but I wonder what happens with sets of longer numbers. > > > > > > > I just tried it with a larger set.. > > {2,2,2,3,6,6,8,8,10,12,12,14,16,19,22,25,28,28,32,33} > > results are Lucius - 3, 12, 22 > > Juergen and I got 6, 12, 23.5 > > 123 and Excel give 6, 12, 22.75 > > > > Regards Pete > > > > and since the results seem to get closer with a larger sample... > with > {2,2,2,3,6,6,8,8,10,12,12,14,16,19,22,25,28,28,32,33,34,35,36,38,40,41,45,48,49,51,53,56,57,57,57,59,61,61,62,62} > Lucius - 10, 33.5, 51 > Juergen and I got 12, 33.5, 52 > 123 and Excel give 12, 33.5, 51.5 > > Maybe I should run this as a competition! >
include sort.e function quartile(sequence data,integer whichOne) -- matches what Excel returns integer lowerObs atom interPoint data=sort(data) if whichOne=0 then return data[1] -- min elsif whichOne=4 then return data[$] -- max elsif whichOne<0 or whichOne>4 then return 1/0 -- invalid else interPoint=(3+length(data))/4 lowerObs=floor(interPoint) interPoint-=lowerObs return (1-interPoint)*data[lowerObs]+interPoint*data[lowerObs+1] end if end function
HTH define an ldata integer to use instead of $ under 2.4. CChris