[R-sig-Geo] gwt2nb - regions with zero links

Dennis Guignet dguignet at arec.umd.edu
Tue Oct 19 05:52:28 CEST 2010


Roger, 

Thank you for the suggestions.  I recently discovered that the issue was that I had included unique ids for some neighbors in the gwt file that were not included in the vector defining the unique ids that was inputted into the gwt2nb function.

Everything worked great (including the observations with no neighbors) after I made sure the same set of observations used to define the vector of unique ids were used creating the neighbor list.  

Thanks again for your help.

Denny

-----Original Message-----
From: Roger Bivand [mailto:Roger.Bivand at nhh.no] 
Sent: Sunday, October 17, 2010 4:14 PM
To: Dennis Guignet
Cc: r-sig-geo at stat.math.ethz.ch
Subject: Re: [R-sig-Geo] gwt2nb - regions with zero links

On Mon, 11 Oct 2010, Dennis Guignet wrote:

> Dear All,
>
> My end goal is to run a spatial lag model, where the weight matrix will 
> be nonsymmetric and contain observations with zero neighbors.  I am 
> having some difficulties in creating the neighbor list in R.  Any advice 
> or pointers on where to find more information would be greatly 
> appreciated.

Maybe try some other format, such as the MATLAB-style sparse matrix in 
read.dat2listw(). However then you cannot use your codes, just the 
sequence 1:n. If this doesn't help, put the file(s) on a website and post 
the link - debugging without the input data is hard. I can't follow how a 
region with only zero links has non-zero links (below).

Roger

>
> I needed to account for both time and space when defining a list of 
> neighbors, and did so first using ArcInfo and then SAS, and saved the 
> final list as a dbf.  It seems I next want to convert this dbf into a 
> neighbor list in R, and was told the best thing to do is save the dbf as 
> a gwt file and change the header line.  A brief portion is pasted below:
>
> 0 34451 nfred3 DGID
> 105450   105578   1
> 105451   105763   1
> 105451   105627   1
> 105451   105899   1
> 105451   105898   1
> 105451   105915   1
> 105452   105763   1
> 105452   105841   1
>
> nfred3 is the name of the gwt file, and DGID is the unique id for each 
> observation.  There are a total of 34,451 unique observations, some of 
> which do not have any neighbors and are thus not included in the above 
> gwt file.  If I run gwt2nb accounting for these zero link observations I 
> get the following warning messages:
>
>> DGID<-sales$dgid
>> length(DGID)
> [1] 34451
>> n2n<-read.gwt2nb("nfred3.gwt", region.id=DGID)
> Warning messages:
> 1: In read.gwt2nb("nfred3.gwt", region.id = DGID) :
>  region.id not named DGID
> 2: In read.gwt2nb("nfred3.gwt", region.id = DGID) :
>  105462, 105463, 105466, 105468, 105472, ...  [... truncated]
> 3: In read.gwt2nb("nfred3.gwt", region.id = DGID) :
>  105450, 105454, 105455, 105462, 105468, ... [... truncated]
>
> The issue is that there are a total of 1,555 regions with no links, but 
> 1,090 of these regions should have a positive number of links .  The 
> truncated list in the warning message contains id numbers that should 
> have zero links, as well as some that should have nonzero links.
>
> If I run similar code but only account for observations with nonzero 
> links, then I have the correct number of nonzero links. So this neighbor 
> list at first glance seems correct, but I still need to account for 
> observations with zero links when later forming the weights, and I am 
> concerned about the below warning messages.
>
>> #create vector of unique sale ids with nonzero spatial link (i.e. has neighbors)
>> n2n0<-read.table("nfred4.gwt",header=FALSE,skip=1)
>> DGID<-unique(n2n0$V1)
>> length(DGID)
> [1] 33986
>> n2n<-read.gwt2nb("nfred4.gwt", region.id=DGID)
> Warning messages:
> 1: In read.gwt2nb("nfred4.gwt", region.id = DGID) :
>  region.id not named DGID
> 2: In read.gwt2nb("nfred4.gwt", region.id = DGID) :
>  105450, 105454, 105455, 105470, ... [... truncated]
>
> Any advice or pointers of where I can find some helpful info would be 
> greatly appreciated.
>
> Thank you,
> Denny
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, 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