Re: Percentiles

Michael Kiefte <[email protected]> Sat, 27 Mar 2004 10:48:11 -0400
Newsgroups gmane.comp.gnu.fiasco.devel
Message-ID <[email protected]>
Here's a small survey of results for the 25th pctile:

R: 53.5
MATLAB: 52.25
SPSS (V11.5): 51

However, I did the 25th percentile of 1 2 3 4 5 and got these results:
R: 2
MATLAB: 1.75
SPSS: 1.5

So SPSS is not using the naive algorithm.

It looks like it's the same basic algorithm for all three except for the=20
initial value of the index.

Index for zero-based array:
R:      (n - 1) * probs
MATLAB: uses an interpolation function that's hard to interpret
SPSS:   (n + 1)*probs - 1

This corresponds with the your tutorial's example as well.

=46rom Ben's e-mail:
> Otherwise, we have tp - cp1 < 100/W and the p'th percentile is:
>         (1 - ((W+1)*p/100 - cc1) * x1) + ((W+1)*p/100 - cc1) * x2

This seems to correspond with what's described, except that it's taking int=
o=20
account the weights or frequencies, which we should be doing too.  I'm sorr=
y=20
I didn't look at that more closely, but it was pretty opaque.  I should be=
=20
getting the book soon as well.

We should definitely use SPSS's definition, but it's interesting to look at=
=20
what it's doing:

     1.      2.      3.      4.      5.

     00      25      50      75      100               R
     00    25        50        75    100               MATLAB
     00  25          50          75  100               SPSS

So SPSS's version kind of lacks esthetic appeal whereas MATLAB appears to=20
split the difference.

Sorry about the confusion.  I really thought there was only one definition.

=2D M.


On Saturday 27 March 2004 00:05, you wrote:
> On Fri, Mar 26, 2004 at 10:57:02AM -0400, Michael Kiefte wrote:
>
>      At least my definition is consistent with SPSS.
>
> I'm not convinced !!!
>
>
> I don't have a copy of SPSS, but I have a tutorial book, which uses
> the following example data set:
>
>  75.00 ,
>  66.00 ,
>  47.00 ,
>  80.00 ,
>  72.00 ,
>  51.00 ,
>  43.00 ,
>  60.00 ,
>  75.00 ,
>  70.00 ,
>  30.00 ,
>  68.00 ,
>  80.00 ,
>  56.00 ,
>  77.00 ,
>  64.00 ,
>  74.00 ,
>  76.00 ,
>  45.00
>
> I ran this through your algorithm and got the 25th percentile:  53.50
>
> In my book however, the sample SPSS printout gives 51.00 which is what
> you'd get if you used the more naive algorithm:
>
>
> double
> pctile(double *x, size_t n, double q)
> {
>   /* make sure q is between 0.0 and 1.0 inclusive */
>
>   double idx =3D (n-1)*q;
>   int lo =3D (int) idx;
>
>   qsort(x, n, sizeof(double), cmp);
>
>   return x[lo];
> }
>
>
> The book says it's based on SPSS Version 11.0
> If anyone's got a copy of SPSS would they care to try this:
>
> DATA LIST LIST  /SALES * .
> BEGIN DATA.
>  75.00
>  66.00
>  47.00
>  80.00
>  72.00
>  99.00
>  51.00
>  43.00
>  60.00
>  75.00
>  70.00
>  30.00
>  68.00
>  80.00
>  56.00
>  77.00
>  64.00
>  74.00
>  76.00
>  45.00
> END DATA.
>
> MISSING VALUE sales (99.0) .
>
> FREQUENCIES
>         VARIABLES=3Dsales
>  	/PERCENTILES =3D 25 50 75.
>
> FINISH.