Y 轴随 R 中 geom_density 中的带宽变化

Y-axis changes with bandwidth in geom_density in R

据我了解,密度曲线下的面积应始终等于 1。这在 R 中似乎并非如此。

我的代码如下所示:

p <- ggplot() +
  geom_density(data = data_plot, aes_string(x = "value", color = group_by),
               position = "identity", size = 0.5, na.rm = TRUE) +
  labs(x = data_plot$unit[data_plot[, group_by] == group_member[1]], y = "density") +
  scale_colour_manual(values = color) +
        theme_own()
plot(p) 

当我将 geom_density 输入更改为

geom_density(data = data_plot, aes_string(x = "Wert", color = group_by),
               position = "identity", size = 0.5, na.rm = TRUE, bw = bandwidth)

我在 y 轴上得到了不同的值。

无手动黑白:

Bw = 0.01:

Bw = 0.00001:

我是不是理解错了什么?我确实希望 y 轴的范围随着带宽的增加而变大(因为许多值在 67 和 100),但曲线不应该更低吗?例如,在最后一个图中,面积约为 30(x 轴)*100(y 轴)=3'000。

概率密度曲线下的总面积确实应该始终为 1。但是,此限制仍然允许 y 轴上的密度值超过 1,因为您必须将高度乘以您感兴趣的密度区域与相应区域的宽度(通常通过求解积分来完成)

例如,考虑范围从 0 到 0.1 的均匀分布。此处,常数密度值为 10,因为 0.1 * 10 = 1。

# example: the shorter the interval between min and max, the larger the 
# the density value becomes
  curve(dunif(x = x, min = 0, max = 0.1), from = 0, to = 0.1)

通过代码中的带宽参数,您实际上是在使感兴趣的区间越来越小,从而导致越来越高的密度值。