[R-sig-eco] nearest neighbours
Anna Marburg
marburga at landcareresearch.co.nz
Sun Sep 27 23:59:49 CEST 2009
Hi Katia -
The spdep package has a variety of functions to count neighbors, as
well as functions to combine neighborhoods.
You will first need to extract the coordinates of your .ppp into a
matrix
Here's a quick example:
library(spatstat)
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) # a matrix of co-ordinates
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)
# look at result
summary(k4, coords)
plot(k4, coords)
# 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)
# test the effect of different set logic
summary(intersect.nb(k4, close.nb), coords)
summary(union.nb(k4, close.nb), coords)
If you are doing more spatial analyses within R, you may want to check
out the following references. There's also a dedicated mailing list
for questions about "geographical data and mapping", R-sig-Geo.
Bivand, R. S., E. J. Pebesma, and V. Gómez-Rubio. 2008. Applied
spatial data analysis with R. Springer Verlag, NY.
Baddeley, A. 2008. Analysing spatial point patterns in R. Workshop
Notes [available from http://www.csiro.au/resources/Spatial-Point-Patterns-in-R.html
]
HTH,
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: 1
> Date: Fri, 25 Sep 2009 11:31:08 -0400
> From: K?tia Emidio <kat.emidio at gmail.com>
> Subject: [R-sig-eco] nearest neighbours
> To: r-sig-ecology at r-project.org
> Message-ID:
> <cf3004ea0909250831n38dfd0bbl853e43d4b382da8d at mail.gmail.com>
> Content-Type: text/plain
>
> Hi, What function should I use to find out who are my 5 nearest
> neigbours(N)
> or in a specified radius, in a .ppp (object) where the marks are
> factors?
> thanks
> Katia
>
> --
> K?tia Em?dio da Silva MSc
> Eng. Florestal
> Pesquisador
> Embrapa Amaz?nia Ocidental
>
> [[alternative HTML version deleted]]
>
>
More information about the R-sig-ecology
mailing list