Skip to content
Prev 10470 / 29559 Next

spatial clusters

On Mon, 20 Dec 2010, dorina.lazar wrote:

            
Using your corrected list of countries, I see two/three problems:

1) some proximate polygons do not touch because of line generalisation in 
the simplification of the country polygons, use:

nbe <- poly2nb(country, snap=0.1)

to force neighbours to touch.

2) you are left with three real islands - Iceland, Cyprus, and Malta. To 
join them in, consider:

knn4 <- knn2nb(knearneigh(crds, 4, longlat=TRUE),
   row.names=row.names(country))
knn4s <- make.sym.nb(knn4)
nbe1 <- union.nb(nbe, knn4s)

3) nbcosts() does not like single-column data frames, as it is supposed to 
be for multivariate data, so:

de <- data.frame(rnorm(46))
ce <- nbcosts(nbe1, de)
which(sapply(ce, function(x) isTRUE(any(is.na(x)))))

gives an NA at the end of each line of cost distances, but:

de <- data.frame(rnorm(46), rnorm(46))
ce <- nbcosts(nbe1, de)
which(sapply(ce, function(x) isTRUE(any(is.na(x)))))
le <- nb2listw(nbe1, ce, style="B")

doesn't, nor does:

de <- data.frame(rnorm(46), rep(1, 46))
ce <- nbcosts(nbe1, de)
which(sapply(ce, function(x) isTRUE(any(is.na(x)))))
le <- nb2listw(nbe1, ce, style="B")