[英]How to calculate percentile in R?
In R help help(quantile)
,you can see 在R help
help(quantile)
,您可以看到
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? 您如何使用7型公式得出结果?
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. 我的问题是分位数的默认值为type = 7,而您已经有了该结果。 If you look at the code for quantile.default there is a section for type=7:
如果您查看分位数代码,则默认为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]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.