[R-sig-Geo] Create distance 'neighborhood' (zone of indifference) when clustering binary data
Roger Bivand
Roger.Bivand at nhh.no
Mon Nov 21 09:29:23 CET 2011
On Sun, 20 Nov 2011, Alberto Gallano wrote:
> Hi, i'm trying to do join count analysis on binary data, but i'd like to
> create neighborhood's of 'indifference' of 100 meters around each spacial
> point.
>
> I've been using dnearneigh to create a neighbor list and knearneigh to
> calculate the maximum of the nearest neighbor distances for the upper bound
> argument to dnearneigh (so that no observations become islands).
>
> My question is, how do I create neighborhoods based on distance? Should I
> just input a number into the upper bound argument of dnearneigh, without
> first using knearneigh? If so, what number would correspond to 100 meters
> (Euclidean)? (btw, the coordinates are already projected).
If you mean that you define neighbours as points j within 100m of point i,
then:
datnb <- dnearneigh(coords, 0, 100)
will do this if your coordinates are measured in metres. This doesn't work
for your example, because the closest points are almost 1200m apart, so no
point has any neighbours for this definition. However, your mentioning
neighborhoods of 'indifference' makes me uncertain that this is what you
mean. Do you mean placing a buffer around each point before finding
neighbours?
Roger
>
> Here is a small subsample of my data and analysis. Thanks,
>
> Alberto
>
>
>
> # ==========================
> # data
> dat <- structure(list(present = c(0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L,
> 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 1L), x = c(332940L, 316301L,
> 312714L, 306008L, 312248L, 329276L, 329663L, 341535L, 314761L,
> 332898L, 332957L, 328332L, 312462L, 330063L, 317808L, 336216L,
> 333763L, 315049L, 333855L, 324406L), y = c(4305226L, 4303010L,
> 4316685L, 4309006L, 4319255L, 4311208L, 4316837L, 4306055L, 4301051L,
> 4300625L, 4330342L, 4303420L, 4308292L, 4307181L, 4292904L, 4304336L,
> 4313750L, 4297998L, 4314941L, 4315051L)), .Names = c("present",
> "x", "y"), class = "data.frame", row.names = c(1L, 2L, 3L, 4L, 5L, 6L,
> 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L))
>
>
> library(spdep)
> coords <- cbind(dat$x, dat$y)
> k1 <- knn2nb(knearneigh(coords))
> maxD <- max(unlist(nbdists(k1, coords))) # upper bound distance btw
> neighbors
> datnb <- dnearneigh(coords, 0, maxD)
> summary(datnb)
> print(is.symmetric.nb(datnb))
>
> datlistw <- nb2listw(datnb, glist=NULL, style="B", zero.policy=TRUE)
>
> # join count
> joincount.test(as.factor(dat$present), datlistw, zero.policy=TRUE,
> alternative="greater", spChk=NULL, adjust.n=TRUE)
> # =========================
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list