5
$\begingroup$

Can anyone help me how to compute 25$^{\text{th}}$, 50$^{\text{th}}$, 75$^{\text{th}}$ and 90$^{\text{th}}$ perecentile of a dataset.

    data = {1.13, 1.24, 1.25, 1.27, 1.28, 1.29, 1.3, 1.36, 1.39, 1.42, 
  1.48, 1.48, 1.49, 1.49, 1.5, 1.5, 1.51, 1.52, 1.53, 1.54, 1.55}
$\endgroup$
4
  • 7
    $\begingroup$ Quantile[data, #] & /@ {0.25, 0.5, 0.75, 0.9} See also Quartiles[data] $\endgroup$
    – Bob Hanlon
    Jan 12 at 6:17
  • 5
    $\begingroup$ Another syntax variation allows a list of quantities: Quantile[data, {1/4, 1/2, 3/4, 9/10}] $\endgroup$
    – Syed
    Jan 12 at 7:09
  • $\begingroup$ Percentile is not exactly the same as Quantile, even if closely related. One issue, other than the obvious 100 scale factor, is that "Percent" is also a Quantity "Unit". Probably this should not be closed? $\endgroup$
    – rhermans
    Jan 12 at 10:08
  • $\begingroup$ +5/-0 votes and a +3 vote answer, why should this stay closed? $\endgroup$
    – rhermans
    Jan 17 at 9:26

1 Answer 1

3
$\begingroup$

Percentile is closely related to fractile or Quantile, except for the scaling 1 to 100 on the argument and the possibility that such arguments could be a "Percent"age unit from Quantity.

Here I define Percentile to also accept Quantity with explicit "Percent" "Units" and also so it works in operator form.

ClearAll[Percentile];
Percentile[data_List, pc_Quantity]:= Quantile[data, QuantityMagnitude[pc/100, "Percent"]]
Percentile[data_List, pc_]:= Quantile[data, pc/100]
Percentile[pc_]:= Percentile[#,pc]&


Percentile[data, {25,50,75,90}]
(* {1.29,1.48,1.5,1.53} *)

Percentile[data, Quantity[99, "Percent"]]
(* 1.55 *)

Percentile[25] @ data
(* 1.29 *)

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.