spatial clusters
On Mon, 20 Dec 2010, dorina.lazar wrote:
Dear all, Finally, with your help, I make some progress to apply SKATER algorithm to European countries. Here is the R code, following the example from spdep package pdf:
country<-wrld_simpl[wrld_simpl$ISO3%in%c("AZE", "ALB", "ARM", "BIH",
"BGR", "CYP", "DNK", "IRL", "EST", "AUT", "CZE", "FIN", "FRA", "GEO", "DEU", "GRC", "HRV", "HUN", "ISL", "ITA", "LVA", "BLR", "LTU", "SVK", "LIE", "MLT", "BEL", "AND", "LUX", "MCO", "NLD", "NOR", "POL", "PRT", "ROU", "MDA", "RUS", "SVN"),]
ske<-spCbind(country, rclasif) ske at data de <- data.frame(scale(ske at data[13])) #col 13 contains the health
indicator (from rclasif)
nbe <- poly2nb(country) ce <- nbcosts(nbe, de) le <- nb2listw(nbe, ce, style="B", zero.policy=TRUE)
Error in nb2listw(nbe, ce, style = "B", zero.policy = TRUE) : neighbours and glist do not conform
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")