[英]R - Get joint probabilities from 2D Kernel Density Estimate
I have two vectors S and V, and using the function kde2d
, I get the following plot of their joint density: 我有两个向量S和V,并使用函数kde2d
,我得到他们的联合密度的下图:
Using this data, is it possible to obtain an empirical estimate of the joint probability, in the form P(S[i],V[j]) ? 使用这些数据,是否有可能以P(S [i],V [j])的形式获得联合概率的经验估计?
In the question How to find/estimate probability density function from density function in R it is suggested we use approxfun
to get the height of a value in a 1D KDE plot. 在如何从R中的密度函数中找到/估计概率密度函数的问题中 ,建议我们使用approxfun
来获得1D KDE图中的值的高度。 Is there a way to extend this idea to 2 dimensions? 有没有办法将这个想法扩展到2维?
One approach would be to use bilinear interpolation of the grid returned by kde2d
: 一种方法是使用kde2d
返回的网格的双线性插值 :
library(fields)
points <- data.frame(x=0:2, y=c(0, 5, 5))
interp.surface(k, points)
# [1] 0.066104795 0.040191482 0.001943069
Data: 数据:
library(MASS)
set.seed(144)
x <- rnorm(1000)
y <- 5*x + rnorm(1000)
k <- kde2d(x, y)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.