Skip to content
Prev 201689 / 398503 Next

Concave hull

On Nov 25, 2009, at 7:51 PM, David Winsemius wrote:

            
And as a further note you can drop the bandwidth and lower the density  
level to get a tighter fit:

xx <- runif(10000, -1, 1)
yy <- abs(xx)+rnorm(10000   ,0,.2); plot(xx,yy, xlim=c( min(xx)- 
sd(xx), max(xx)+sd(xx)), ylim =c( min(yy)-sd(yy), max(yy)+sd(yy)),  
cex=.2)

dens2 <- kde2d(xx, yy, lims=c(min(xx)-sd(xx), max(xx)+sd(xx), min(yy)- 
sd(yy), max(yy)+sd(yy) ) , h=c(bandwidth.nrd(xx)/4, bandwidth.nrd(xx)/ 
4) )
contour(dens2, add=TRUE)
#  You can pick a single contour if you like:

contour(dens2, level=0.05, col="red", add=TRUE)
contour(dens2, level=0.10, col="blue", add=TRUE)

contour(dens2, level=0.005, col="red", add=TRUE)


(More bat-like.)