5

I am trying to use ecdf, but I am not sure if I am doing it right. My ultimate purpose is to find what quantile corresponds to a specific value. As an example:

sample_set <- c(20, 40, 60, 80, 100) 
# Now I want to get the 0.75 quantile:
quantile(x = sample_set, probs = 0.75)
#result:
75% 
80
# Let's use ecdf
ecdf(x = sample_set) (80)
#result
0.8

Why is there this discrepancy? Am I doing some trivial mistake, or it depends on the way quantile makes its calculations?

Thanks, Max

1
  • 1
    Maybe the calculations would make more sense if you looked at plot(ecdf(x = sample_set)); abline(h = 0.75,col = "blue")? Certainly one (or both) of those directions is ambiguous...?
    – joran
    Mar 10, 2016 at 22:05

1 Answer 1

5

There are two points. First, as you guessed, it depends on the way quantile makes its calculations. Specifically, it depends on the parameter type. What you might want to choose is type = 1, since then it corresponds to the inverse of empirical distribution function (see ?quantile). Second, since ecdf gives a discrete, step function, i.e. the ecdf is not strictly increasing, you cannot get exact equality because of the way quantile is defined (see the second formula).

2
  • I assume you mean the ecdf is not strictly increasing. Its an increasing function in the often used sense of monotonic non-decreasing.
    – A. Webb
    Mar 10, 2016 at 22:10
  • @A.Webb, yes, that is what I meant. I will add this word to avoid confusion. Mar 10, 2016 at 22:19

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.