[R-sig-Geo] Question about "col.gal.nb" object

Roger Bivand Roger.Bivand at nhh.no
Mon May 14 09:53:21 CEST 2012


On Sat, 12 May 2012, Tom Gottfried wrote:

> Am 11.05.2012 19:58, schrieb Eder Gerardo Quiñones Sanchez:
>> Hi,
>> 
>> i'm using the 'col.gal.nb' object for the definition of all neighbors. my
>> information is loaded from a archives into may pc
>
> Though someone might accidentally know what col.gal.nb is and where it comes 
> from, having told us here would have been much nearer to 'reproducible'.
>
>> *library(spdep)*
>> *
>> *
>> *city<- readOGR(dsn="C:/cities", layer="city1")*
>> *coords<- coordinates(city)*
>> *
>> *
>> *plot(col.gal.nb, coords, add=TRUE)*
>> *Error: length(nb) == nrow(coords) is not TRUE*
>
> If you refer to the documentation of the plot method you are using here, I 
> suspect you find out that 'nb' refers to the first argument and 'coords' to 
> the second. The error message tells you they need to fulfil the condition 
> given in the message ('length(nb) == nrow(coords)' is actually an R 
> expression!).

The questioner is using the help files without understanding them. My 
guess is that instead of reading:

      example(columbus)
      coords <- coordinates(columbus)
      plot(col.gal.nb, coords)

from ?plot.nb in spdep, and grasping that col.gal.nb came from 
example(columbus), and so is (?columbus):

      col.gal.nb <- read.gal(system.file("etc/weights/columbus.gal",
       package="spdep")[1])

that is a GAL file of neighbours as output by OpenGeoDa and other 
applications, the questioner is assuming that it appears by itself. Both 
?read.gal and indeed class(col.gal.nb) say that it is a list of 
neighbours.

Now, unless you get lucky - or unlucky, as the case may be - the number of 
objects whose neighbours are listed in the "nb" object, and the number of 
rows (observations) in the user's own data will not match, hence the 
error. The user has to generate a new list of neighbours suiting the data 
set in question, using one of the functions in spdep, or indeed by reading 
the input shapefile into OpenGeoDa and generating a GAL file there. Which 
definition of neighbour to use depends on the research question - if the 
data are for example census tracts in a city, poly2nb() may be a good 
place to start.

Hope this clarifies,

Roger

>
> HTH,
> Tom
>
>> but when i try to draw it, an error appears. i don't know what could be the
>> error...
>> 
>> 
>> 
>> 
>> _______________________________________________
>> 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, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no


More information about the R-sig-Geo mailing list