[R-sig-eco] creating cluster with between points arbitrary distances

Nicholas Lewin-Koh nikko at hailmail.net
Thu Dec 10 17:59:59 CET 2009


Hi Alex,
Well in the example you show, almost any distance based
clustering method would identify the relationship, from your example
dd<-dist(cbind(x,y))
cuttree(hclust(dd),2)

However, what I think you are after is simply thresholding. So
if x are your bird coordinates, then,
library(igraph)
x<-matrix(rnorm(100,sd=10),nc=2)
dd<-dist(x)
dd[dd>=5]<-0 #threshold at at dist=5
g<-graph.adjacency(as.matrix(dd),weighted=TRUE,mode='upper') # create an
undirected thresholded graph
plot(g) # look at it
clusters(g)## Find the connected components (eg your clusters)

Nicholas



> Date: Wed, 09 Dec 2009 21:32:50 +0100
> From: "alexandre villers" <alexandre.villers at cebc.cnrs.fr>
> Subject: [R-sig-eco] creating cluster with between points arbitrary
> 	distances
> To: r-sig-ecology at r-project.org
> Message-ID: <1260390770.82a01d4alexandre.villers at cebc.cnrs.fr>
> Content-Type: text/plain; charset="UTF-8"
> 
> Good evening,
> 
> I'm still working on the spatial distribution of an aggregated bird
> species. I would like to test different between birds distances to create
> clusters and thus identify groups of birds (leks). It would be "visually"
> quite easy to do it but I would like to repeat this clustering
> objectively for many years in order to characterize some biological
> processes. So I would like for example to group all the birds who share
> neighbours in less than 1000 meters in the same cluster. Thus, 3 birds
> lying on a straight line 700 meters from each other would belong to the
> same cluster (hope this is clear).
> 
> I can get groups of points whose distances are below a certain threshold
> with dnearneigh() from package "spdep" but this would still require to
> write an iterative function to group points. 
> Is there an existing function that can do the whole trick? I know many
> packages are available for clustering with R but I haven't found one that
> I can parametrize in a such way yet.
> 
> Any link will be appreciated.
> Thanks
> 
> 
> Alex
> 
> P.S.: to get this visually
> 
> x<-c(0,700,1400, 3000)
> y<-c(0,0,0,0)
> plot(y~x, col=c("red","red", "red", "black"), pch=c(16,16,16,16)) # red
> points belong to the same cluster while the black doesn't
> Alexandre Villers
> PhD. Candidate
> Team Agripop
> CEBC CNRS UPR 1934
> 79360 Beauvoir sur Niort
> 
> Phone: +33 (0)549 099 613 
> 
> 
> __________ Information from ESET Mail Security, version of virus
> signature database 4674 (20091209) __________
> 
> The message was checked by ESET Mail Security.
> http://www.eset.com
> 
> 
>



More information about the R-sig-ecology mailing list