Exact kernel density value for any point in R [duplicate]

孤者浪人 提交于 2019-12-21 06:05:12

问题


I was wondering if there is a R base way to obtain the exact kernel density at any point desired? As an example, how can I get the exact kernel density at the 3 following points -2, 0, +2 on X-Axis in a plot like below?

set.seed(2937107)
plot( density(rnorm(1e4)) )


回答1:


Use linear interpolation to find it.

d <- density(rnorm(10000))
approx(d$x, d$y, xout = c(-2, 0, 2))

The precision of interpolation can be higher if you set a larger n in density. By default n = 512 so interpolation is based on 512 points.



来源:https://stackoverflow.com/questions/43862665/exact-kernel-density-value-for-any-point-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!