Max_IT
Max_IT

Reputation: 626

quantile vs ecdf results

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

Upvotes: 6

Views: 2388

Answers (1)

Julius Vainora
Julius Vainora

Reputation: 48211

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

Upvotes: 5

Related Questions