Skip to content
Prev 7156 / 29559 Next

creating cluster with between-points arbitrary distances

Hi Alexandre,

Greetings from yesterday evening.

I think I know what you want, and I've been working on the same problem
in a very different substantive context. To make sure I understand the
question, you are basically stating that if the gap between "nearest"
birds of the same species exceeds 1000 meters, then the two birds cannot
be considered to be in the same cluster. Returning to your example of
birds along a straight line, assume the birds run from A to B to C, and
A and B are 700 meters apart, while B and C are 1001 meters apart, then
it is the case that A and B are in a cluster, but C is not a member of
that cluster.

Assuming what I said is correct, one thing you can do is create a
relative neighbor graph of your points, and then drop any edges from the
graph that exceed 1000 meters. This will create a set up unconnected
sub-graphs, and the points within each sub-graph constitutes a cluster.
I've written a function (using the spdens package) that removes the long
edges from the relative neighbor graph, there by creating the set of
clusters. I've pasted my function below (at some point I will create an
R package that includes this function, but it is likely a couple of
months away).

The function follows:

# dropLongLinks takes an nb (neighbor list) object, the original
coordinates,
# and a maximum distance, then removes links from the nb object for
links that
# exceed the maximum distance.

# Programer: Dan Putler
# Created: 08Feb09
# Modified: 08Feb09

dropLongLinks <- function(nb, coords, max.dist) {
    require(spdep)
    if(!is.matrix(coords)) coords <- as.matrix(coords)
    dists <- nbdists(nb, coords)
    nb.new <-
      lapply(1:length(nb), function(i) nb[[i]] <- nb[[i]][dists[[i]] <=
max.dist])
    class(nb.new) <- "nb"
    return(nb.new)
    }
On Thu, 2009-12-10 at 07:50 +0100, Alexandre VILLERS wrote: