Skip to content

Instantly share code, notes, and snippets.

@Framartin
Created October 25, 2015 16:58
Show Gist options
  • Save Framartin/d6a8d7847f360a2960dc to your computer and use it in GitHub Desktop.
Save Framartin/d6a8d7847f360a2960dc to your computer and use it in GitHub Desktop.
Renormalization issue
library(spdep)
data(oldcol)
lw <- nb2listw(COL.nb)
attr(lw, "region.id")
region.id.wanted.order <- attr(lw, "region.id")[c(1:41, 44:49, 42, 43)] # cannot be obtain with subset.listw
# we convert it to a Matrix and re-normalized it with mat2listw()
W <- as(lw, "CsparseMatrix")
W <- W[region.id.wanted.order, region.id.wanted.order]
style <- lw$style
lw1 <- mat2listw(W, row.names = region.id.wanted.order, style = style) # re-normalize to keep the style
lw2 <- subset.listw(lw1, attr(lw1, "region.id") != "1043") # not working
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment