[R-sig-Geo] globalG.test - plotting from routine
Francesco Perugini
francescoperugini07 at gmail.com
Wed Feb 3 15:08:07 CET 2016
Dear all,
I've a routine (see below) that computes the Global G statistics for
different k-neighbor spatial matrix and for different variables.
Now I want to plot (for each var) the difference between Global G statistic
computed at k neighbour with the one computed at k-1 on the y-axes, with
the number of k on the x-axis.
I guess I need to extract the Global G statistics from the ZG lists and
then plot them.This is my attempt:
library(rlist)
list(ZG)
list.extract(ZG,'var$estimate[1]')
plot(c(var$estimate[1], border="grey60",xlab="k",ylab="Global G statistic",
xlim=NULL, axes=TRUE)
title(main="Global G at different k")
Any suggestion on this?
Thanks a lot.
franc.per
_____________
this is the routine:
library(spdep)
example(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)))
}
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(columbus[[var]], dlwknn.B,
zero.policy=F)))
}
ZG[[val]] <- temp
}
t(sapply(lapply(ZG, "[[", 1), function(var) c(var$estimate[1],
var$statistic,
p.value=unname(var$p.value))))
t(sapply(lapply(ZG, "[[", 2), 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