r-spatial / spdep

Spatial Dependence: Weighting Schemes and Statistics
https://r-spatial.github.io/spdep/
116 stars 26 forks source link

Error in print.listw(x) : regions with no neighbours found, use zero.policy=TRUE #126

Closed swaheera closed 1 year ago

swaheera commented 1 year ago

Hello!

I am running the following code:

lw <- nb2listw(nb, style="W", zero.policy=TRUE)

But I am getting this error:

Error in print.listw(x) : 
  regions with no neighbours found, use zero.policy=TRUE

However, I have already specified zero.policy = TRUE?

Am I doing something wrong?

Thanks!

rsbivand commented 1 year ago

You need to use zero.policy = TRUE every time you use a probably defective neighbour or spatial weights object. You can also set an option for the current session, set.ZeroPolicyOption, https://r-spatial.github.io/spdep/reference/set.spChkOption.html, if you really intend to proceed with no-neighbour observations, then all functions will act as if the argument zero.policy = TRUE has been used (default FALSE). Tests in spdep do by default adjust n for the consequences of no-neighbour observations, but other implementations vary in how they handle this poorly-studied problem.

swaheera commented 1 year ago

@rsbivand : thank you so much for your reply!

In my example, can you please recommend how to use this option? For example

set.ZeroPolicyOption(nb)

Is this correct?

Thanks!

rsbivand commented 1 year ago

set.ZeroPolicyOption(TRUE) sets the arguments to TRUE for all functions.

Meghna88 commented 1 year ago

Hi R> library("spdep") R> W.nb <- poly2nb(WBSF, row.names = WBSF$ID_B)

When I run the above mention code for spatio-temporal models (trying to create neighbourhood matrix W), the following error is occurred:

Error in wk_handle.wk_wkb(wkb, s2_geography_writer(oriented = oriented, : Loop 0 is not valid: Edge 3680 has duplicate vertex with edge 3683

How to resolve the problem? Thanks!

rsbivand commented 1 year ago

Do not join an irrelant issue, start another if, having read https://r-spatial.github.io/spdep/reference/poly2nb.html#note-1, you cannot solve this yourself (your input geometry in in ellipsoidal coordinates, see also https://r-spatial.org/book/04-Spherical.html). If still stuck, create a new issue with a minimal reproducible example.

gadouaka commented 1 year ago

Bonsoir, j ai eu un probleme apres executé le code suivant: nb <- poly2nb(Carte, row.names = SMR.av$CODE) , list.nb <- nb2listw(nb, style = "B", zero.policy = TRUE)

print(list.nb) Error in print.listw(list.nb) : regions with no neighbours found, use zero.policy=TRUE

gadouaka commented 1 year ago

comment dois je resoudre ce probleme?

gadouaka commented 1 year ago

Bonsoir, j'ai exécuté le code suivant: list.nb <- nb2listw(nb, style = "B", zero.policy = TRUE) et le message suivant s'affiche: print(list.nb) Error in print.listw(list.nb) : regions with no neighbours found, use zero.policy=TRUE. Aidez moi, svp a resoudre ce probleme. Merci

rsbivand commented 1 year ago

See #128 #129