0
$\begingroup$

How would you differentiate between the quantile function and cumulative percentage below? Note the treatment of numerics as categorical when grouping is performed.

When would you use one over the other?

Am i right to read the first (quantile ) as 90% of the population would have a number below 13.6 and the 2nd (cumulative perc) as 90% of the number would be 4 and below?

The difference between the 2 being, the quantile estimates, whereas the cumulative perc does not?

nums = c(0, 1,1,1, 3,3,3,3, 4,100)
quantile(nums,seq(.1, 1, .1))

#  10%   20%   30%   40%   50%   60%   70%   80%   90%  100% 
#  0.9   1.0   1.0   2.2   3.0   3.0   3.0   3.2  13.6 100.0

library(dplyr)
data.frame(nums = nums) %>% 
  group_by(nums) %>% 
  summarise(freq = n()) %>% 
  ungroup() %>% 
  mutate(pct = freq / sum(freq), cumsum_pct = cumsum(pct)) 

# A tibble: 5 x 4
# nums  freq   pct cumsum_pct
# <dbl> <int> <dbl>      <dbl>
#  1     0     1   0.1        0.1
# 2     1     3   0.3        0.4
# 3     3     4   0.4        0.8
# 4     4     1   0.1        0.9
# 5   100     1   0.1        1 
$\endgroup$
  • 1
    $\begingroup$ Please consult the help page for quantile, ?quantile, and study the meaning of its type argument. $\endgroup$ – whuber Nov 29 '18 at 0:51
  • $\begingroup$ Thanks whyber. Unfortunately my self-learn capacity is limited. Concepts and example is what makes sense at the moment. fyi, i did search the help function. but interpreting it was difficult for me. $\endgroup$ – JimmyR Nov 29 '18 at 2:34
1
$\begingroup$

The key argument of quantile to check out is type. From its help page:

type
an integer between 1 and 9 selecting one of the nine quantile algorithms detailed below to be used.

The default type is 7, which is for continuous samples. You are using a discontinuous sample, so if you pass type=1 you get a result that matches your self-computed cumsum_pct.

quantile(nums,seq(.1, 1, .1), type = 1)
 10%  20%  30%  40%  50%  60%  70%  80%  90% 100% 
   0    1    1    1    3    3    3    3    4  100 
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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