[R-sig-Geo] create nb object

Roger Bivand Roger.Bivand at nhh.no
Thu Dec 17 13:45:36 CET 2009


On Thu, 17 Dec 2009, Pete Larson wrote:

> 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?

class(test)
?nb2listw

Neighbourhood "nb" just says that there is a link, not the weight to put 
on it. Use nb2listw() to make the weights "listw" object, after 
considering the options available. If the actual process doesn't match 
your guess, you may not be able to model it adequately. Is the choice of 
first nearest neighbour considered, as you see, the neighbour 
relationships are not symmetric? Are your points in geographical or 
projected coordinates - it does make a difference? Marine fish data are 
often in geographical coordinates (so use longlat=TRUE), but yours are 
fresh-water?

Roger

>
> 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
>>> 
>> 
>
>

-- 
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