获取R中一组点的上凸包

Getting the upper convex hull of a set of points in R

我正在尝试在 R 中获取与生产力数据相关的一组点的上凸包。我希望它是一个按比例递减 returns 的函数,输入是工时,输出是对完成工作的衡量。我想要上凸包,因为这可以让我获得效率边界。

我搜索并找到了 R 中的 chull 方法,但这给出了整个包络中的点集,而不仅仅是上船体点。有没有办法自动 select R 中的上壳点?

举个例子,我们可以找到一个点在一个圆上生成的上壳

library(ggplot2)
# Generate random uniformly spaced points in the square space between (0,0) and (1,1)
x <- runif(10000, min = 0, max = 1)
y <- runif(10000, min = 0, max = 1)
df <- tibble(x,y)
# Filter out the points that don't lie inside a circle of radius 1
df %>% filter(!(x^2+y^2>1)) -> df
# Plot all the points in the above dataframe
ggplot(df, aes(x=x, y=y)) + geom_point()
# Compute the convex hull of the above points
newdf <- df[chull(df$x, df$y),]
# Plot the convex hull
ggplot(newdf, aes(x=x, y=y)) + geom_point()

完整的情节是这样的

凸包看起来像这样

在这个例子中,upper hull 应该只给我圆的弯曲部分而不是轴

在这种情况下,您可以 select 线上方的点 1 - x

plot(newdf[newdf$y > 1 - newdf$x, ])


另一种近似上凸包的方法是改变你的初始过滤方法,只得到 1 和例如 1 之间的值。 0.995,然后得到凸包:

df <- with(df, df[(x^2+y^2 < 1 & x^2+y^2 > 0.995),])
plot(df[chull(df$x, df$y),])

这里有一个方法,使用将x-axis切割成小块的方法,然后计算每个块的mean(x)和max(y)... 你可以 inceals/decrease 块的数量,以获得更平滑(或更详细)的线条。

library(tidyverse)
df %>%
  mutate(bin = cut(x, 10)) %>%  # !! <-- increase/decrease value
  group_by(bin) %>%
  summarise(max_y = max(y, na.rm = TRUE),
            x_max_y = mean(x, na.rm = TRUE)) %>%
  ggplot(aes(x = x_max_y, y = max_y)) + geom_point()

n = 50 个箱