R - Get joint probabilities from 2D Kernel Density Estimate

5.1k views Asked by At

I have two vectors S and V, and using the function kde2d, I get the following plot of their joint density:

Joint probability density of <code>S</code> and <code>V</code>

Using this data, is it possible to obtain an empirical estimate of the joint probability, in the form 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. Is there a way to extend this idea to 2 dimensions?

1

There are 1 answers

0
josliber On BEST ANSWER

One approach would be to use bilinear interpolation of the grid returned by 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)