[R-sig-Geo] Problems with read.gal

Roger Bivand Roger.Bivand at nhh.no
Fri Mar 25 11:53:31 CET 2016


On Thu, 24 Mar 2016, Ann Hartell wrote:

> Hello All,
>
> I'm having issues getting R to properly read a GAL file.  GeoDa is
> reading the file and correctly assigning neighbors, calculating various
> spatial statistics, etc.  I've checked the GAL file for any coding
> anomolies (using a short Perl program), and all seems well.
>
> After the usual preliminaries of loading packages (e.g. spdep v.
> 0.5-92), setting a working directory, reading in the SHP file . .  .
>
> ##  read into R as an nb object following the Usage in the spdep help file:
>
> queen.nb <- read.gal("MyShapeFile.GAL", region.id=NULL, override.id=FALSE)
>
>
> ##Returns this error:
>
> Error in read.gal("MyShapeFile.GAL", region.id = NULL, override.id =
> FALSE) : GAL file IDs and region.id differ

Assuming that you constructed the file in GeoDa (which?), could you make 
it available off-list for forensics? Maybe a small change somewhere is 
creating problems?

Roger

>
> ##In the past, I have had success following the example
> ## from Anselin linked in the spdep help at <
> https://geodacenter.asu.edu/system/files/rex1.pdf  >
>
> queen.nb <- read.gal("MyShapeFile.GAL", override.id=TRUE)
> queen.listW <- nb2listw(queen.nb, style="W", zero.policy = TRUE)
> class(queen.listW)
>
> [1] "listw" "nb"
>
> summary(queen.listW)
>
>
> Characteristics of weights list object:
> Neighbour list object:
> Number of regions: 39361
> Number of nonzero links: 238004
> Percentage nonzero weights: 0.01536215
> Average number of links: 6.046696
> Non-symmetric neighbours list
> Link number distribution:
>
>    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17
>  217  640 2041 4804 8062 8752 7196 4194 1863
>
>
> ###. . . .  and so on . . . .
>
> ## Plotting a contiguity map reveals the trouble
>
> plot(data, border="grey60")
> title(main="Queen contiguity")
> plot(queen.listW, coord, add=TRUE, col="green", pch=19, cex=0.6)
>
> ### Far flung spatial units are linked as neighbors, which is incorrect.
> ###  I get the same jumble results using:
>
> queen.nb <- read.gal("MyShapeFile.GAL", region.id = NULL, override.id=TRUE)
>
> ### Then, following the example provided here:
> http://cran.at.r-project.org/web/packages/spdep/vignettes/nb.pdf
>
> MyFile <- readShapeSpatial("MyShapeFile")
> library(spdep)
> queen.nb <- read.gal("MyShapeFile.GAL", region.id = row.names(MyFile))
>
> ## Returns:
>
> Error in read.gal("MyShapeFile.GAL", region.id = row.names(test)) : GAL
> file IDs and region.id differ
>
>
> #######End
>
> So, an issue with the id variables between the two files, but I cannot
> work out how to resolve it.
> Any insights or elaboration on the Usage and Arguments provided in the
> spdep help most appreciated.
> Thanks,
> Ann Hartell
>
>

-- 
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
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
http://depsy.org/person/434412



More information about the R-sig-Geo mailing list