[R-sig-Geo] globalG.test - x vector with different lenght as the neighbours list

Francesco Perugini francescoperugini07 at gmail.com
Tue Feb 2 16:15:17 CET 2016


Dear all,
I've a routine to create spatial weight matrix for different k and then to
implement, for each of the created spatial weighted matrix, the Global G
test for autocorrelation.
The point is that I'll try to do this test on multiple variables but then
lenghts are different

> length(dlwknn.B$neighbours)
[1] 49
> length(var)
[1] 1

Any help on how to code this?
Thanks a lot.
franc.per90


______________________________
This is the routine:

library(spdep)
example(columbus)
#data(columbus)
#attach(columbus)
coord <- coordinates(columbus)


z <- c(1,2,3,4,5,6,7,8,9)
neighbors.knn <- list()

for (val in z)
  {
  neighbors.knn <- c(neighbors.knn, list(knn2nb(knearneigh(coord, val,
longlat=F), sym=F)))
}

class(neighbors.knn)

class(neighbors.knn[[1]])
plot(neighbors.knn[[1]], coord)

class(neighbors.knn[[2]])
plot(neighbors.knn[[2]], coord)
....


ndists <- length(z)
ZG <- vector(mode="list", length=ndists)
names(ZG) <- as.character(z)

f <- c(CRIME, INC)
for (val in z) {
  dlwknn.B <- nb2listw(neighbors.knn[[val]], style="B", zero.policy=TRUE)
  temp <- list()

  for (var in f)
  {
    temp <- c(temp, list(globalG.test(var, dlwknn.B, zero.policy=F)))
  }
  ZG[[val]] <- temp
}

t(sapply(ZG, function(var) c(var$estimate[1], var$statistic,
p.value=unname(var$p.value))))

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list