Percentiles (finally getting to understand it).

John Darrington <[email protected]> Tue, 30 Mar 2004 12:57:06 +0800
Newsgroups gmane.comp.gnu.fiasco.devel
Message-ID <[email protected]>
--===============1330349763==
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="tKW2IUtsqtDRztdT"
Content-Disposition: inline


--tKW2IUtsqtDRztdT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Well I think I've finally  worked out what the=20
"SPSS Statistical Algorithms" text must have meant.

I think it's the following simple C func.

double=20
pctileSPSS(double *x, size_t n, double q)
{

  double tp =3D (n + 1) * q -1;
  int lo;
 =20
  lo =3D (int) floor(tp);

  qsort(x, n, sizeof(double), cmp);

  assert( lo >=3D-1);
  assert(lo <=3D (int) n);

 if ( lo > n - 1)=20
   return x[n-1];

 if ( lo =3D=3D -1 )=20
   return x[0];

  return x[lo] + (x[lo+1]-x[lo]) * (tp-lo);
}


This seems to return the same answers as all the available SPSS
examples.  As Michael mentioned however it is inelegent to put it
politely!!

Percentiles near the 50th are fine, but the others get squeezed away
from the median.  And so there has to be the two special cases to cope
with percentiles near 0 and 100  (for a small data set, the 85th
percentile will be the same as the 100th) .

Quite frankly it's a croc!  I much prefer Michael's definition (also
used by R), which doesn't use any special cases.

I suggest that PSPP uses the R definition unless the
--bug-for-bug-spss-compatibility option was requested.

John




--=20
PGP Public key ID: 1024D/2DE827B3=20
fingerprint =3D 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://wwwkeys.pgp.net or any PGP keyserver for public key.



--tKW2IUtsqtDRztdT
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFAaP4iimdxnC3oJ7MRAutQAJ9sR4GWTyiMUE4jp1M+eUsWo/PODACeMB9C
ZgWuUPFqJEUxE+AdZ7h3BBo=
=EMc9
-----END PGP SIGNATURE-----

--tKW2IUtsqtDRztdT--



--===============1330349763==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
pspp-dev mailing list
[email protected]
http://mail.gnu.org/mailman/listinfo/pspp-dev

--===============1330349763==--