Skip to content

how to get my subset?

2 messages · zhijie zhang, Roger Bivand

#
On Sun, 9 Apr 2006, zhijie zhang wrote:

            
x<-rnorm(20)
y<-cell2nb(4,5)
s1 <- sample(1:length(x), 4)
x_s1 <- x[s1]
y_s1 <- subset(y, 1:length(x) %in% s1)

(but with such a small sample, very few neighbour links will remain)
look at attr(y, "region.id") to choose the subset, do:

rc <- do.call("rbind", strsplit(attr(y, "region.id"), ":"))

to extract the IDs as a character row, column matrix.

I'm not sure why sampling is useful here, simulations on Moran's I are 
usually done by permutations on the x values, for example by 
permutation bootstrap. There are examples among other places in 
the DCluster and spdep packages, in spdep in the example to function 
moran.mc().