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 questio"/>
I have two vectors S and V, and using the function kde2d
, I get the following plot of their joint density:
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?
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.