Concave hull
On Nov 25, 2009, at 7:51 PM, David Winsemius wrote:
Drats; Forgot the plot: xx <- runif(100, -1, 1) yy <- abs(xx)+rnorm(100,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))) dens2 <- kde2d(xx, yy, lims=c(min(xx)-sd(xx), max(xx)+sd(xx), min(yy)-sd(yy), max(yy)+sd(yy) ) ) 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)
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.)
David. > > > > On Nov 25, 2009, at 7:46 PM, David Winsemius wrote: > >> This is not a true convave hull, but a 2D density is something >> similar and perhaps more "statistical": >> >> library(MASS) >> xx <- runif(100, 0, 1) >> xx <- runif(100, -1, 1) >> yy <- abs(xx)+rnorm(100,0,.2) >> dens2 <- kde2d(xx, yy, lims=c(min(xx)-sd(xx), max(xx)+sd(xx), >> min(yy)-sd(yy), max(yy)+sd(yy) ) ) >> 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) >> >> >> Happy Valentine's >> -- >> David >> >> On Nov 25, 2009, at 11:37 AM, Corrado wrote: >> >>> Dear friends, >>> >>> Do you know how to calculate the CONCAVE hull of a set of points (2- >>> dimensional or n-dimensional)? is that possible in R? (With a >>> "smoothing" >>> parameter of course). >>> >>> Best, >>> -- >>> Corrado Topi >>> >>> Global Climate Change & Biodiversity Indicators >>> Area 18,Department of Biology >>> University of York, York, YO10 5YW, UK >>> Phone: + 44 (0) 1904 328645, E-mail: ct529 at york.ac.uk >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >> David Winsemius, MD >> Heritage Laboratories >> West Hartford, CT >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > David Winsemius, MD > Heritage Laboratories > West Hartford, CT > David Winsemius, MD Heritage Laboratories West Hartford, CT