Skip to content
Prev 795 / 7420 Next

nearest neighbours - amended

Hello again Katia -

Of course, before you can use the functions in spdep, you will need to  
load it, like this:

library(spatstat)
library(spdep)
data(amacrine)

ama.split <- split(amacrine) # make one .ppp for each mark
summary(ama.split)

coords <- cbind(ama.split[["on"]]$x, ama.split[["on"]]$y)
class(coords)

rn <- 1:nrow(coords)	# if your points have meaningful ids put them here

# find 4 nearest neighbors:
k4 <- knn2nb(knearneigh(coords, k = 4), row.names = rn)

# calculate distances from each point to its neighbors
dsts <- nbdists(k4, coords)
summary(unlist(dsts))


# find all neighbors closer than some threshold
close.nb <- dnearneigh(coords, 0, 0.12330, row.names=rn)

# what do these different neighborhood objects look like?
summary(k4, coords)
summary(close.nb, coords)


# test the effect of different set logic
summary(intersect.nb(k4, close.nb), coords)

summary(union.nb(k4, close.nb), coords)


Sorry for the error,

Anna


Dr. Anna E.  Marburg
Ecosystem Processes Team
Landcare Research
P O Box 40
Lincoln 7640
NEW ZEALAND

phone + 64  3 321 9729
MarbugA at landcareresearch.co.nz
Message-ID: <59570A3D-946B-4D43-ACFA-466A29F30A10@landcareresearch.co.nz>
In-Reply-To: <mailman.3.1253959201.9982.r-sig-ecology@r-project.org>