spdep "Not yet able to subset general weights lists" listw

2.5k views Asked by At

I have a problems with spdep(). Starting with a matrix of non-missing distances produced by a function

dist_m <- geoDistMatrix(data1, group = 'fips_dist')
dist_m[upper.tri(dist_m)] <- t(dist_m)[upper.tri(dist_m)]

we then turn into weights with linear inverse

max_dist <- max(dist_m)
w1 <- (max_dist + 1 - dist_m)/(max_dist + 1)

and now

lw <- mat2listw(w1, row.names = rownames(w1), style = 'M')

I check to make sure no missing weights:

any(is.na(lw$weights))

and since there aren't, go ahead with:

errorsarlm(cvote ~ inc, data = data1, lw, method = 'eigen', quiet = F, zero.policy = TRUE)

leads to the following error:

Error in subset.listw(listw, subset, zero.policy = zero.policy) : 
  Not yet able to subset general weights lists
2

There are 2 answers

0
MERose On

This is because at least one observation in data1 is not complete, i.e. has missing values. Hence, errorsarlm wants to subset the data, i.e. restrict to complete cases. But it can't do it now - that's what the error message says.

Best is to subset the data manually or correct the incomplete cases.

0
Enrico Dace On

This is because the spdep function created a listw object only for non-general weights by default. Set zero.polcy=TRUE beform you perform mat2listw or nb2listw function so that it consider non-neighbors that have zero value.