Reputation: 320
In R helphelp(quantile)
,you can see
Type 7 m = 1-p. p[k] = (k - 1) / (n - 1). In this case, p[k] =mode[F(x[k])].
This is used by S.
now ,i have a example:
w<-c(75,64,47.4,66.9,62.2,62.2,58.7,63.5,66.6,64,57,69,56.9,50,72.0)
sort(w)
[1] 47.4 50.0 56.9 57.0 58.7 62.2 62.2 63.5 64.0 64.0 66.6 66.9 69.0 72.0 75.0
quantile(w)
0% 25% 50% 75% 100%
47.40 57.85 63.50 66.75 75.00
How can you use the type 7 formula to get the result?
Upvotes: 1
Views: 19317
Reputation: 263471
I'm having some trouble deciding if the answer is just:
> quantile(w, type=7)
0% 25% 50% 75% 100%
47.40 57.85 63.50 66.75 75.00
My problem is that the default for quantile is type=7 and you already have that result. If you look at the code for quantile.default there is a section for type=7:
index <- 1 + (n - 1) * probs
lo <- floor(index)
hi <- ceiling(index)
x <- sort(x, partial = unique(c(lo, hi)))
qs <- x[lo]
i <- which(index > lo)
h <- (index - lo)[i]
qs[i] <- (1 - h) * qs[i] + h * x[hi[i]]
Upvotes: 2