R:如何获得特定的密度估计

R: how to obtain specific density estimates

# The Old Faithful geyser data
d <- density(faithful$eruptions, bw = "sj")
> head(d$x)
[1] 1.179869 1.188363 1.196857 1.205350 1.213844 1.222338

我在 {stats} 中使用 density 函数,我想知道是否可以在输出中看到特定值的密度?例如,目前,我有 [1] 1.179869 1.188363 ... 喷发值的密度估计值,但如果我想知道喷发值 1 2 5 10 ... 的密度估计值怎么办?有没有办法提取这些 density 对象,d?

如果我没理解错的话,您想要 x 值等于某个数字(在我的解决方案中为 3 或 4)的概率?

d <- density(faithful$eruptions, bw = "sj")
densityDF <- data.frame(xVals = d$x, prob = d$y)
densityDF$xVals <- round(densityDF$xVals)

densitySearch <- densityDF[densityDF$xVals %in% c(3,4),]

结果:

   xVals       prob
157     3 0.11229482
158     3 0.10721410
159     3 0.10230912
160     3 0.09765156
161     3 0.09318662
162     3 0.08891621