6

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

Max_IT
  • 602
  • 5
  • 15
  • 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 '16 at 22:05

1 Answers1

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).

Julius Vainora
  • 47,421
  • 9
  • 90
  • 102