I wanna integrate the 2d probability density function calculated from Gaussian kde. I use the kernel density function from stats.gaussian_kde()
x = location["longitude"]
y = location["latitude"]
xmin = -87.9
xmax = -87.5
ymin = 41.6
ymax = 42.05
xx, yy = np.mgrid[xmin:xmax:100j, ymin:ymax:100j]
positions = np.vstack([xx.ravel(), yy.ravel()])
values = np.vstack([x, y])
kernel = stats.gaussian_kde(values)
f = np.reshape(kernel(positions).T, xx.shape)
This code calculates a 2-d pdf(kernel) value for me, but does not give a probability in a specific area(data range). For example, I wanna get a probability of data range (-87.9, 41.6) to (-87.7, 41.7). But how can I integrate it as this data range seems to be a 1-d straight line? The integration value for any data range should be 0, as it is a 1-d line. I wonder if there is any solution to get a probability from the 2d KDE function.
I know there is kde.integrate_box(), but I think it has a limitation that the angle of the rectangle diagonal, which means the 1-d line connected from data range[0] to data range[1], affects to integrated value because the area of the rectangle varies depending on the angle.
Also, I had heard about scipy.integrate.nquad(), but I am still confused. Can you give me some information about the integration method for 2d kde?