Re: Mathematica's Quantile[] vs. Matlab's prctile()
- From: "Steven Lord" <slord@xxxxxxxxxxxxx>
- Date: Mon, 10 Dec 2007 17:24:40 -0500
"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 Quantilefunction 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
.
- Follow-Ups:
- Re: Mathematica's Quantile[] vs. Matlab's prctile()
- From: caveman
- Re: Mathematica's Quantile[] vs. Matlab's prctile()
- References:
- Prev by Date: Re: Mathematica's Quantile[] vs. Matlab's prctile()
- Next by Date: Re: Simple question about solving simultaneous equations
- Previous by thread: Re: Mathematica's Quantile[] vs. Matlab's prctile()
- Next by thread: Re: Mathematica's Quantile[] vs. Matlab's prctile()
- Index(es):
Relevant Pages
|