# NOT RUN {
if (require(rgdal, quietly=TRUE)) {
example(nc.sids, package="spData")
sidsrate79 <- (1000*nc.sids$SID79)/nc.sids$BIR79
dists <- c(10, 20, 30, 33, 40, 50, 60, 70, 80, 90, 100)
ndists <- length(dists)
ZG <- vector(mode="list", length=ndists)
names(ZG) <- as.character(dists)
milesxy <- cbind(nc.sids$east, nc.sids$north)
for (i in 1:ndists) {
thisnb <- dnearneigh(milesxy, 0, dists[i])
thislw <- nb2listw(thisnb, style="B", zero.policy=TRUE)
ZG[[i]] <- globalG.test(sidsrate79, thislw, zero.policy=TRUE)
}
t(sapply(ZG, function(x) c(x$estimate[1], x$statistic, p.value=unname(x$p.value))))
for (i in 1:ndists) {
thisnb <- dnearneigh(milesxy, 0, dists[i])
thislw <- nb2listw(thisnb, style="B", zero.policy=TRUE)
ZG[[i]] <- globalG.test(sidsrate79, thislw, zero.policy=TRUE, alternative="two.sided")
}
t(sapply(ZG, function(x) c(x$estimate[1], x$statistic, p.value=unname(x$p.value))))
}
# }
Run the code above in your browser using DataLab