Skip to content
Prev 10041 / 29559 Next

Creating very large spatial weight matrix

On Thu, 18 Nov 2010, Aleksandr Andreev wrote:

            
The actual answer is to use the function needed for this operation:

library(spdep)
coords <- cbind(Lon, Lat)
dnb <- dnearneigh(coords, 0, dmax, longlat=TRUE)

where dmax is a small distance in km. Of course, if you really need all 
the distances, all bets are off, but this would be an unusually specified 
picture of the underlying spatial process. I suggest not worrying about 
ensuring that all observations have at least one neighbour - for such a 
global measure as Moran's I for N=120', dropping a few cannot matter much. 
Go with a tight dmax, and it should just work. If dmax is loose, and the 
average number of neighbours creeps up, the nb object (and the following 
listw object) will get denser, with possibly some observations with 
thousands of neighbours, so oversmoothing the process.

If this is continental rather than whole-world, consider projecting to the 
plane and using graph-based neighbours (?graph2nb).

Hope this helps,

Roger