[英]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
I'm using density
function in {stats}
, and I'm wondering if it's possible to see density at specific values in the output? 我在{stats}
使用了density
函数,并且想知道是否可以在输出中看到特定值的密度? For example, currently, I have density estimates at eruption values of [1] 1.179869 1.188363 ...
but what if I want to know the density estimates at eruption values 1 2 5 10 ...
? 例如,当前,我有喷发值[1] 1.179869 1.188363 ...
的密度估计,但是如果我想知道喷发值1 2 5 10 ...
的密度估计怎么办? Is there a way to extract these the density
object, d
? 有没有办法提取这些density
对象d
?
If I understand you correctly, you want the probabilities where the x value equals some number (3 or 4 as in my solution)? 如果我理解正确,那么您想要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),]
Result: 结果:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.