Re: Mathematica's Quantile[] vs. Matlab's prctile()




"Dave" <foo@xxxxxxx> wrote in message news:475d72e4@xxxxxxxxxxxxxxxx
From what I gather, there is no universally agreed definition of
percentile. Is there one which more people use than another?

I've been calculating the 5th percentile of some data in Mathematica using
the Quantile[] function.

In[1]:= t={1,2,1000,100000}

Out[1]= {1, 2, 1000, 100000}

In[2]:= Quantile[t,.5]

Out[2]= 2


Doing similar in Matlab with prctile() gives a very different result -
y=[1 2 1000 100000]


prctile(y,50)

ans =

501

So one gives 2, the other 501.

I've picked a set of data which maximises the differences - I think with a
larger range of more similar data, the differences will be much smaller.

From looking at the Mathematica documentation, it looks like its Quantile
function multiplies your quantile percentage (0.5) by the length of the list
(4), takes the ceiling of that value (in this case, 2) and returns that
element of the list. For the syntax you used, it's just indexing -- no
interpolation is performed.

http://documents.wolfram.com/mathematica/functions/Quantile

The help text for the PRCTILE function in MATLAB ("help prctile") indicates
that it interpolates your data to return the appropriate percentile. For
your y data set, it treats the four elements as the 12.5th, 37.5th, 62.5th,
and 87.5th percentile and performs linear interpolation to determine the
value corresponding to the 50th percentile.

N = 4;
p = (100/N)*((1:N)-0.5);
x = [1 2 1000 1001];
interp1(p, x, 50)

You can see the interpolation from this graph:

plot(p, x, 'go-', 50, interp1(p, x, 50), 'r+')

--
Steve Lord
slord@xxxxxxxxxxxxx


.



Relevant Pages

  • RE: Interpolate in table lookup
    ... PERCENTILE has been a native Excel function since XL97 but you need to try a ... value inside the data range for interpolation to make sense. ... I tried PERCENTILE, ... non-lineararity to be significant. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Strange behaviour of <=?
    ... I have a vector from which I want to store the values below some percentile. ... So I tried both quantile() and prctile() like this: ...
    (comp.soft-sys.matlab)
  • Re: Strange behaviour of <=?
    ... I have a vector from which I want to store the values below some percentile. ... So I tried both quantile() and prctile() like this: ... can you produce a copy/paste-able example of typical SMALL data set and a complete loop... ...
    (comp.soft-sys.matlab)
  • Re: Strange behaviour of <=?
    ... I have a vector from which I want to store the values below some percentile. ... So I tried both quantile() and prctile() like this: ... It was the original data file that was a little bit screwed up. ...
    (comp.soft-sys.matlab)
  • Re: Quartile (percentile) algorythm
    ... given by reference to percentile function, then what is the algorythm for ... QUARTILE uses the same method as PERCENTILE. ... excerpts from Excel's Help: ... interpolation is standard linear interpolation. ...
    (microsoft.public.excel.worksheet.functions)