Error in nb2listw(W.nb, style = "W") : Empty neighbour sets found

What can cause this problem?

I'm doing an analysis of a SAR model. So, I imported a shape of an area but when I do this:

library(rgdal)
library(spdep)

W.nb <- poly2nb(shape.SP, row.names = rownames(shape.SP@data))
W.list <- nb2listw(W.nb,style="W")

The W.list returns an error. What does this error mean?

In technical sense you are hitting issue with your zero policy - your shapefile seems to contain areas with zero neighbors, with zero.policy on default.

You should be able to make this error go away (in technical sense) by using nb2listw(W.nb,style="W", zero.policy = TRUE).

I would suggest to look into the root cause: does your shapefile contain any islands? or topological inconsistencies? It may - and may not, depending on your use case - be a good idea to address these in a pre-processing.

1 Like

I guess that was the thing. I had to use this command. Thanks for your helping!

However, when I do it:

SARmodel <- lagsarlm(obitos ~ pop_60 + area, data=SP, W.list)

Occurs that error:

Error in lagsarlm(obitos ~ pop_60 + area, data = SP, W.list) : NAs in lagged dependent variable
In addition: Warning message:
In lag.listw(listw, y, zero.policy = zero.policy) : NAs in lagged values

Do you have some idea of how to solve this? I think there is some NA value in a cell, but there isn't. I visually checked all my data from my database. So, I think the problem could be in my shapefile.

That's my code:

SP1 <- read.csv("26012021.csv", header = TRUE, sep = ";", dec = ",")

SP <- SP1[(-646),]

shape.SP <- readOGR("C:/Users/lucas/Desktop/IC - Silvio/R/sp_municipios","SP_Municipios_2019")

W.nb <- poly2nb(shape.SP, row.names = rownames(shape.SP@data))
W.list <- nb2listw(W.nb, style="W", zero.policy = TRUE)

SARmodel <- lagsarlm(obitos ~ pop_60 + area, data=SP, W.list)

The variables are in portuguese because I'm brazilian, but this is irrelevant.

I'm not understand, as well, how is my database linked with the shapefile as I make the lagsarlm procedure. Is something wrong in my code?

Thanks for everything.

The result you describe - NAs in lagged variable - are directly related to your previous error. Since you have regions with no neighbours there are NAs in your lagged variables.

Does your shapefile contain any islands? Fernando de Noronha comes to my mind as a possible culprit. It may be necessary to filter these out, and run your regression only on continental Brazil.

1 Like

Yes. It does. There are some islands, but Fernando de Noronha isn't in that region that I'm working with. Fernando de Noronha is located in the northeast region of Brazil and not in that southeast region that I am dealing with. Anyway, How can I remove/filter out the islands of my shapefile? This file is with an extension that I don't know how to use: ".shp". Do you have some idea?

Look at my shapefile. There are some islands on the right bottom.

Well, Fernando de Noronha is the only Brazilian island I know by name :slight_smile:

I believe the easiest way to remove the islands is by downloading QGIS (www.qgis.org) and editing the little islands out.

QGIS can both read & write the *.shp data files (ESRI Shapefile) and for an editing job like this it is better to actually see what you are doing.

1 Like

Hehehehe, It's one of the most famous islands of Brazil. Another one is Florianópolis, located in the South of the country.

Thank you! I'm gonna study it! I will download QGIS and try to do this. Just one question:
The shape's folder of that region contains files with those extensions: cpg, dbf, prj, shp, shx.
When I edit the shapefile, all of those extensions will be edited as well? Because i can only run "readOGR" with that combination of files.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.