我有
x=rnorm(100)
y=rnorm(100)
plot(x,y)
abline(h=0); abline(v=0)
从点 (0,0)
向外我想绘制一个轮廓/圆/椭圆/手绘凸包,它包含任何给定百分比的点。
是否有任何函数或包可以自动执行此操作?到目前为止,我已经尝试了以下方法,但我只能通过一些外推和近似得到一个圆。
到目前为止我已经试过了:
#calculate radius
r<- sqrt(x^2+y^2)
df<-data.frame(radius=seq(0,3,0.1), percentage=NA)
#get the percentage of points that have a smaller radius than i
k<-1
for (i in seq(0,3,0.1)){
df$percentage[k] <- sum(r<i)/length(r)
k<-k+1
}
#extrapolation function
prox.function<- approxfun(df$percentage, df$radius)
#get the radius of the circle that encloses about 50% of
prox.function(.50)
#draw the circle
library(plotrix)
draw.circle(0,0,prox.function(.50))
最佳答案
包围分数 f 的点的半径是:
f <- 0.5 # use half for this example as in the question
sort(r)[ ceiling(f * length(r)) ]
关于r - 围绕给定百分比的点绘制圆/凸包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30301108/