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")