Skip to content

Inverse distance weights and spatial error model-update

4 messages · Adam Boessen, Roger Bivand

#
My apologies for the duplicate list, but I forgot to use plain text in my last post, and thus there was a problem posting to archive.  Here is the post now:

Hi Everyone,
I'm new to R, so thank you in advance for your patience.  I'm using US census block groups in Buffalo New York to examine how neighborhood characteristics affect crime.  I would like to use an inverse distance weights (distance decay) of block group centroids that is banded at 1 kilometer.  In other words, I would like to create a one kilometer buffer around each of the centroids, then use row standardized inverse distance weights.  Finally, I would like to run a spatial error model using these weights.  

Here is my code:
[1] "bgidfp00"     "gage2900"     "gavghhinc00"  "gblack00"     "gcrwd00"     
 [6] "gethhet00"    "ghhincsdln00" "glatino00"    "gocc00"       "gowner00"    
[11] "gpop00"       "gpov00"       "assaul"       "robber"       "burglr"      
[16] "motveh"       "murder"       "larcen"       "x"            "y"
Neighbour list object:
Number of regions: 409 
Number of nonzero links: 5298 
Percentage nonzero weights: 3.167126 
Average number of links: 12.95355 
1 region with no links:
12
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 22 23 24 25 26 
 1  1  3  3  4  5 14 25 28 23 19 26 32 44 29 24 29 25 24 13 15 12  3  4  1  1  1 
1 least connected region:
3 with 1 link
1 most connected region:
382 with 26 links
Error in nb2listw(inverse, style = "W", zero.policy = TRUE) : 
  Not a neighbours list
2: stop("Not a neighbours list")
1: nb2listw(inverse, style = "W", zero.policy = TRUE)
+ data=buffalo,listw=neigh.listw, zero.policy=TRUE)
Error in eval(expr, envir, enclos) : object 'assaul_r' not found

The model will run when I do not include the code with the inverse weights and only interpoint distances, but it's unclear to me why I can't include the inverse distances when using nb2listw.  Any ideas on why this is occurring and/or help to alleviate this issue would be much appreciated.  The spatial error model from errorsarlm (package=spdep) will also run fine when I don't include the inverse weights.  Is there a better way to go about running this spatial error model using row standardized inverse distance weights?   Would spautolm from the spdep package be better suited for these data?  Any comments or suggestions are welcome.
Thank you for your time!  

Adam

Adam Boessen 
Doctoral Student 
Department of Criminology, Law and Society 
University of California, Irvine 
aboessen at uci.edu

p.s. If it's helpful, here is my version of R:
_                            
platform       i386-apple-darwin9.8.0       
arch           i386                         
os             darwin9.8.0                  
system         i386, darwin9.8.0            
status                                      
major          2                            
minor          10.1                         
year           2009                         
month          12                           
day            14                           
svn rev        50720                        
language       R                            
version.string R version 2.10.1 (2009-12-14)
#
On Sun, 21 Feb 2010, Adam Boessen wrote:

            
Thanks for cooperating about this, keeping to plain text really helps!
I'm assuming that you know definitely that your coordinates are 
geographical not projected - I've seen users adding longlat=TRUE when 
not appropriate.
No, use:

neigh.listw <- nb2listw(neigh.nb, glist=inverse, style="W",
   zero.policy=TRUE)

You pass the list of weights through the glist= argument, as in the 
example for col.w.d in ?nb2listw.
Well, there is no assaul_r in buffalo, is there?

Hope this helps,

Roger

  
    
#
Hi Roger,
Thank you very much for your quick reply and for creating the spdep package.  I tried the tweaks to the code as you note below, but I still get a warning message.  I have reposted my code below with a few more questions:
Warning message:
In nb2listw(neigh.nb, glist = inverse, style = "W", zero.policy = TRUE) :
  zero sum general weights
Warning message:
 
There was nothing listed here.  Is this warning a problem?  I was hesitant about using glist since I didn't think it could be incorporated in the errorsarlm models (hence the error in the code below).   Would using spautolm() help to get around my error below in the model?
Good catch on this one.  I meant to make my crime counts into rates.  I haven't found a package where I can model crime counts as Poisson or negative binomial regressions.  Any suggestions?
Error in subset.listw(listw, subset, zero.policy = zero.policy) : 
  Not yet able to subset general weights lists
4: stop("Not yet able to subset general weights lists")
3: subset.listw(listw, subset, zero.policy = zero.policy)
2: subset(listw, subset, zero.policy = zero.policy)
1: errorsarlm(assaul_r ~ gage2900 + gblack00 + gcrwd00 + gethhet00 + 
       ghhincsdln00 + glatino00 + gocc00 + gowner00 + gpov00, data = buffalo, 
       listw = neigh.listw, zero.policy = TRUE)

 Thanks again for your help!

Adam

Adam Boessen 
Doctoral Student 
Department of Criminology, Law and Society 
University of California, Irvine 
aboessen at uci.edu
On Feb 21, 2010, at 11:38 PM, Roger Bivand wrote:

            
#
On Mon, 22 Feb 2010, Adam Boessen wrote:

            
the 1km threshold. This means that the general weights sum is zero for 
this region. It's a warning, not an error - you've set zero.policy to 
TRUE, so the output is OK assuming that you accept no-neighbour 
observations.
Use disease mapping approaches, usually going out to WinBUGS or BayesX, or 
GLMM through one of the avaliable functions elsewhere in R. We discuss 
this in the final two chapters of our book, code on book website 
www.asdar-book.org. These however do not let you use the spatial weights 
in the same way. If you need these kinds of weights, then maybe the 
spatial filtering or Moran eigenvector approach might help (adding 
selected eigenvectors of the centred weights matrix to the right hand side 
variables in a regular GLM). Using a GLM (or spautolm) also lets you use 
case weights, which would likely be relevant in your case - see also 
Waller & Gotway 2004.
It appears that one or more of your observations has missing values, and 
the function really prefers all observations to be complete. If they are 
not, and the weights are not general, it subsets the data and the weights 
to drop incomplete observations, but cannot do that if the weights are 
general. Use of complete.cases() and subset() before running the model 
will help.

Hope this helps,

Roger