Kde2d density comparison

I have a question about kde2d (Kernel density estimator). I compute two different kde2d for two different datasets in the same variable space. When I compare both with filled path 2 or paths, I see that a set with a lower density of points in the scatter plot (also has fewer points in the total of 10 times) has a higher density for the values โ€‹โ€‹of the paths. I expected a set with a higher point density to have higher values โ€‹โ€‹of the density contours, but, as I said, this is not so. Should it be with a choice of bandwidth (h)? I use equals h and I tried to change, but the result did not change much. What is my mistake?

Example

 a <- runif(1000, 5.0, 7.5) b <- runif(1000, 2.0, 3.0) c <- runif(100000,5.0, 7.5) d <- runif(100000, 2.0, 3.0) library(MASS) abdens <- kde2d(a,b,n=100,h=0.5) cddens <- kde2d(c,d,n=100,h=0.5) mylevels <- seq(-2.4,30,0.9) filled.contour2(abdens,xlab="a",ylab="b",xlim=c(5,7.5),ylim=c(2,3), col=hsv(seq(0,1,length=length(mylevels)))) plot(a,b) contour(abdens,nlevels=5,add=T,col="blue") plot(c,d) contour(cddens,nlevels=5,add=T,col="orange") 
+4
source share
1 answer

I am not sure that I agree that the density should be different in a single case. I would expect that a set with a large number of randomly drawn points from the normal distribution would have more support for extreme areas and, therefore, would have a lower (estimated) density in the center. This effect can also sometimes be manifested with the help of uniform uniform draws with 1000 points versus 100 000. I hope that my changes in your code are acceptable. It is easier to see the contour if this is done after the graphs.

(The theoretical density would be the same in both cases, since the density distribution is normalized to an integral of 1.0. We consider only estimates with some expected artifacts from the "edge" effects. In the case of one-dimensional densities adding information about the boundaries can be performed using desity functions in package :: logspline.)

0
source

Source: https://habr.com/ru/post/1488450/


All Articles