对于一个连续随机变量,用R可以拟合出其密度函数。我想问的是,有没有办法计算出任意一点对应的密度函数值?类似于线性拟合模型的predict()函数的功能。
如何得到任意一点的密度函数值
邮件列表上找到的答案:
If you really just want the density at a single
point, x0 (=1 in your case), you can do
d0 <- density(x, from=x0, to=x0, n=1)$y
(density only lets you choose the output x vector
as an evenly spaced sequence parameterized by
from, to, and n.)
回复 第2楼 的 bravebird:
另一种办法是用ks包:
library(ks);<br />
x = rnorm(1000);<br />
d = kde(x, hpi(x));<br />
dkde(c(0, 1, 2), d);
</p>