Skip to content
Prev 7659 / 29559 Next

Neighborhood weights spam matrix

On Thu, 18 Feb 2010, Nikhil Kaza wrote:

            
If you had saved the output of poly2nb as an nb object, you could have 
used the subset method for that class. You are using default row 
standardisation in the nb2listw() step, so only subsetting grid_nb_mat - 
by using "[" with keep vectors:

keep <- which(shp_file$CELL_ID "... to keep")

kgrid_nb_mat <- grid_nb_mat[keep, keep]

will not have correct row sums. str(grid_nb_mat) shows no row or column 
names stored (probably to save space). If possible start again from 
poly2nb() and save the output object. Otherwise:

example(columbus)
col.listw <- nb2listw(col.gal.nb)
col.sp <- as.spam.listw(col.listw)
str(col.sp)
keep <- c(1:20, 25:40)
kcol.sp <- col.sp[keep, keep]
apply(kcol.sp, 1, sum)
str(kcol.sp)
kcol.sp at entries <- rep(1, 150)
apply(kcol.sp, 1, sum)
rsum <- apply(kcol.sp, 1, sum)
kkcol.sp <- diag.spam(1/rsum) %*% kcol.sp
apply(kkcol.sp, 1, sum)

Roger