[R-sig-Geo] create nb object

Pete Larson pslarson2 at gmail.com
Thu Dec 17 13:38:15 CET 2009


Roger,

OK, I did what you indicated here:

xy<-coordinates(fish)
test<-knn2nb(knearneigh(xy))

with a summary:
summary(test)
Neighbour list object:
Number of regions: 341
Number of nonzero links: 341
Percentage nonzero weights: 0.2932551
Average number of links: 1
Non-symmetric neighbours list

Then I want to run a spatial regression like this:

spautolm(N.fish.spp ~ TEMPannual + Elevation, data=fish, 
family="SAR",listw=test, method="Matrix")

and I get this error:

Error in spautolm(N.fish.spp ~ TEMPannual + Elevation, data = fish, 
family = "SAR",  :
  No neighbourhood list

I thought that the "test" object WAS a neighborhood list?

Any help would be appreciated.

Pete



Roger Bivand wrote:
> On Wed, 16 Dec 2009, Pete Larson wrote:
>
>> Hello all,
>>
>> I have a data frame with lat and lon coordinates for some sample 
>> areas (not a grid) .
>>
>> I was to create an nb object that I can use with spdep but am unsure 
>> as to how to convert it.
>>
>> Does anybody have any ideas?
>
> Create a matrix of coordinates, if not using sp classes, for example:
>
> xy <- cbind(df$x, df$y)
>
> or if your data frame is a SpatialPointsDataFrame, just:
>
> xy <- coordinates(obj)
>
> Then your choice of dnearneigh(), knn2nb(knearneigh()), graph2nb() 
> with three graph variants, tri2nb() for a Delaunay triangulation. The 
> first two of these also take a longlat= argument in case your 
> coordinates are geographical, not projected. Triangulation and 
> graph-based methods need planar coordinates, so you would have to 
> project them first.
>
> Hope this helps,
>
> Roger
>
>>
>> Thanks,
>>
>>
>> Pete
>>>
>>>
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>



More information about the R-sig-Geo mailing list