r-spatial / spdep

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

Warning message Interpretation: knearneigh(x = xy, k = k) : knearneigh: identical points found #11

Closed MariosBarlas closed 6 years ago

MariosBarlas commented 6 years ago

Hello,

I'm running spatial statistics and I get a warning that says:

knearneigh(x = xy, k = k) : knearneigh: identical points found

Does some1 know what it means ? ( I mean mathematically where could it come from )

Thank you!

rsbivand commented 6 years ago

This is not an issue with the software, and should go to R-sig-geo. The help page ?knearneigh does say:

A warning will be given if identical points are found.

for rather obvious reasons (no two spatial observation positions may be at the same point). If you have identical observations by position, this would fail in geostatistics and point pattern analysis too. It is only a warning, so you can proceed, but the warning is to alert the user to a likely data input error.

cypiemarrs commented 2 years ago

How do I specify that I would like to ignore the warning? It would make sense that some points would repeat in the dataset that I am working with, yet it is keeping me from proceeding:

Warning messages: 1: In knearneigh(coords, 3) : knearneigh: identical points found 2: In knearneigh(coords, 3) : knearneigh: kd_tree not available for identical points

rsbivand commented 2 years ago

Please never continue closed issues, and do read and understand the closed issue first anyway.

No, it is only warning you. The object will still be returned, but fast methods using spatial indexing cannot be used in this case, as the warning says:

> library(spdep)
Loading required package: sp
Loading required package: spData
Loading required package: sf
Linking to GEOS 3.10.0rc2, GDAL 3.3.2, PROJ 8.1.1
> data(oldcol)
> coords <- cbind(COL.OLD$X, COL.OLD$Y)
> (o0 <- knn2nb(knearneigh(coords, k=3)))
Neighbour list object:
Number of regions: 49 
Number of nonzero links: 147 
Percentage nonzero weights: 6.122449 
Average number of links: 3 
Non-symmetric neighbours list
> (o1 <- knn2nb(knearneigh(rbind(coords, coords[1:10,]), k=3)))
Neighbour list object:
Number of regions: 59 
Number of nonzero links: 177 
Percentage nonzero weights: 5.084746 
Average number of links: 3 
Non-symmetric neighbours list
Warning messages:
1: In knearneigh(rbind(coords, coords[1:10, ]), k = 3) :
  knearneigh: identical points found
2: In knearneigh(rbind(coords, coords[1:10, ]), k = 3) :
  knearneigh: kd_tree not available for identical points
> length(o1)
[1] 59

Many spatial methods are meaningless when points are duplicated, because the spatial process may give different estimates for the same point. Spatio-temporal data are separated on the temporal dimension.