Has anyone seen a method for creating a neighbor list, for use in spatial auto-correlation tests, that treats the earth as a sphere so that relationships can go shortest distance. I'm trying to make a neighbor list of all countries in the world. Yes I realize that the relatedness may not be distance and I might weight on some other factor but I need the neighbor list to start. Example, US <-> Japan, China or Russia should be a line across the Pacific Perhaps I need to develop the neighbor list using some sort of social diagramming tool instead. Any leads would be appreciated. Thanks, Alex
Spatial auto-correlation globally (sphere)
4 messages · Roger Bivand, Rolando Valdez, Alex Mandel
On Sun, 23 Mar 2014, Alex Mandel wrote:
Has anyone seen a method for creating a neighbor list, for use in spatial auto-correlation tests, that treats the earth as a sphere so that relationships can go shortest distance. I'm trying to make a neighbor list of all countries in the world.
Please start by specifying the support you intend to use (centroid point support, polygonal support, what?). If point support, setting longlat=TRUE in dnearneigh() in spdep with a matrix of coordinates, or using an object inheriting from SpatialPoints with the appropriate CRS will give you Great Circle distances; polygons are more complicated. Have you looked at the cshapes package, also mentioned in the Spatial Task View, which appears to do what you want to do? It has an R Journal article: http://journal.r-project.org/archive/2010-1/RJournal_2010-1_Weidmann+Skrede~Gleditsch.pdf Roger
Yes I realize that the relatedness may not be distance and I might weight on some other factor but I need the neighbor list to start. Example, US <-> Japan, China or Russia should be a line across the Pacific Perhaps I need to develop the neighbor list using some sort of social diagramming tool instead. Any leads would be appreciated. Thanks, Alex
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no
Hi, I?m not sure what kind of data you have. I work with shapes layers. Without more information, I expose you what have I done with my data:
library(rgdal) library(sp) library(spdep) library(lattice) library(RANN) library(maptools)
Checking rgeos availability: TRUE
library(rgeos)
map <-readOGR(".", "zm?) #Reading the shape file.
neigh=poly2nb(map, queen=FALSE)
mapaxy=coordinates(map)
k1=knn2nb(knearneigh(mapaxy, k=1)) #First order matrix weights
dist=unlist(nbdists(k1, mapaxy))
summary(dist)
Min. 1st Qu. Median Mean 3rd Qu. Max. 1021 4359 8492 13510 15290 273900
wdist20=dnearneigh(mapaxy, d1=0, d2=20000) #Consider relationships within a 20km radio. l20=nb2listw(wdist20, style="W", zero.policy=TRUE) #Creating a matrix weights considering 20 km radio. summary(l20, zero.policy=TRUE)
Characteristics of weights list object:
Neighbour list object:
Number of regions: 345
Number of nonzero links: 3296
Percentage nonzero weights: 2.769166
Average number of links: 9.553623
64 regions with no links:
1 2 3 4 25 26 27 28 29 30 31 32 33 34 35 36 37 38 42 44 45 46 47 48 49 56 57 61 62 63 65 66 86 87 88 93 149 150 152 166 167 168 170 172 177 179 228 229 236 237 239 241 242 243 244 284 285 291 298 309 314 315 334 335
Link number distribution:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 26 27 28 29 30 31 33
64 30 21 11 15 20 14 10 9 10 15 12 7 8 10 11 12 9 5 11 2 3 2 1 2 2 4 1 3
34 35 36 37 38
7 3 3 5 3
30 least connected regions:
23 24 40 41 58 59 60 64 148 151 181 202 212 213 224 225 226 227 230 231 232 233 234 235 294 308 322 325 329 333 with 1 link
3 most connected regions:
262 275 282 with 38 links
Weights style: W
Weights constants summary:
n nn S0 S1 S2
W 281 78961 281 126.7744 1149.688
After that, you can to do the autocorrelation test (Moran test) with your statistical data:
test=moran.test(datos$ind_alim, listw=l20, randomisation=TRUE, zero.policy=TRUE) test
Moran's I test under randomisation
data: datos$ind_alim
weights: l20
Moran I statistic standard deviate = 3.762, p-value = 8.428e-05
alternative hypothesis: greater
sample estimates:
Moran I statistic Expectation Variance
0.135908714 -0.003571429 0.001374638
Other option you have, is to create the neighbor list object with GeoDa.
Hope this example helps,
Regards.
Inicio del mensaje reenviado:
De: Alex Mandel <tech_dev at wildintellect.com> Asunto: [R-sig-Geo] Spatial auto-correlation globally (sphere) Fecha: 23 de marzo de 2014 14:46:19 GMT-6 Para: Aide R SIG GEO <r-sig-geo at stat.math.ethz.ch> Responder a: tech at wildintellect.com Has anyone seen a method for creating a neighbor list, for use in spatial auto-correlation tests, that treats the earth as a sphere so that relationships can go shortest distance. I'm trying to make a neighbor list of all countries in the world. Yes I realize that the relatedness may not be distance and I might weight on some other factor but I need the neighbor list to start. Example, US <-> Japan, China or Russia should be a line across the Pacific Perhaps I need to develop the neighbor list using some sort of social diagramming tool instead. Any leads would be appreciated. Thanks, Alex
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Rolando Valdez
Thanks it looks like cshapes might be exactly what I was looking for and more. I thought I knew what most of the Spatial packages were for, clearly there are still a few more to wander through. It's odd that the Task View pages don't have the same short description lines next to packages the way the normal package list on the website does. I think I was leaning towards polygons, I wasn't sure since the wrapping of the dateline was the bigger problem to solve in my mind. Cshapes has an interesting way of doing that where they look for the nearest 2 nodes that make up the borders rather than directly testing polygons or line edges. So it's really all points then. The reason for the package is actually quite similar what I planned to do with it so that paper you linked is very useful. Thanks, Alex
On 03/23/2014 02:41 PM, Roger Bivand wrote:
On Sun, 23 Mar 2014, Alex Mandel wrote:
Has anyone seen a method for creating a neighbor list, for use in spatial auto-correlation tests, that treats the earth as a sphere so that relationships can go shortest distance. I'm trying to make a neighbor list of all countries in the world.
Please start by specifying the support you intend to use (centroid point support, polygonal support, what?). If point support, setting longlat=TRUE in dnearneigh() in spdep with a matrix of coordinates, or using an object inheriting from SpatialPoints with the appropriate CRS will give you Great Circle distances; polygons are more complicated. Have you looked at the cshapes package, also mentioned in the Spatial Task View, which appears to do what you want to do? It has an R Journal article: http://journal.r-project.org/archive/2010-1/RJournal_2010-1_Weidmann+Skrede~Gleditsch.pdf Roger
Yes I realize that the relatedness may not be distance and I might weight on some other factor but I need the neighbor list to start. Example, US <-> Japan, China or Russia should be a line across the Pacific Perhaps I need to develop the neighbor list using some sort of social diagramming tool instead. Any leads would be appreciated. Thanks, Alex
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo