2

I used function quantile in R to do the calculation of 90th, 75th, 50th, 25th percentile, but then my colleague used SAS proc univariate to do the same calculation, we got quite different results (for example, 90th percentile from R is 47.36, but 90th percentile from SAS is 50.64). I'm trying to figure out why. Could anybody give me some guidance on this?

R code:

quantile(c(43.55,41.30,39.40,40.93,38.74,39.97,45.38,41.48,45.01,42.03,44.71,43.42,45.83,43.44,37.84,50.64,53.16,45.95), prob=c(0.90, 0.10, 0.75, 0.50, 0.25))

SAS code:

    data x;
    input x;
    datalines;
    43.55
    41.30
    39.40
    40.93
    38.74
    39.97
    45.38
    41.48
    45.01
    42.03
    44.71
    43.42
    45.83
    43.44
    37.84
    50.64
    53.16
    45.95

    ;
    run;
    proc univariate data=x noprint ;
    var x;
    output out=new  p90=p90 p10=p10 q3=p75 median=p50 q1=p25 ;
    run;
Community
  • 1
  • 1
Kelly Lu
  • 21
  • 3
  • 3
    In R, there is a `type=` parameter for `quantile()`. (There is no one universal definition of what a quantile is.) Try `type=3` (that should match the SAS definition). See `?quantile` for the different definitions. – MrFlick Nov 17 '17 at 21:44

1 Answers1

2

Default method in R is 7 while in SAS default is probably empirical distribution function with averaging .

If you use add option type = 1 in R you will get same result as in SAS.

quantile(c(43.55,41.30,39.40,40.93,38.74,39.97,45.38,41.48,45.01,
           42.03,44.71,43.42,45.83,43.44,37.84,50.64,53.16,45.95),
         prob=c(0.90, 0.10, 0.75, 0.50, 0.25),
         type = 1)
  90%   10%   75%   50%   25% 
50.64 38.74 45.38 43.42 40.93 
Glaud
  • 723
  • 5
  • 9